From d7bb4c10051a8f34869d2f3a91ad55d7d04ff158 Mon Sep 17 00:00:00 2001 From: ibuler Date: Mon, 29 Feb 2016 17:48:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(kill=20invalid=20connection)=20=E7=B4=A7?= =?UTF-8?q?=E6=80=A5=E5=A4=84=E7=90=86=E8=B6=85=E6=97=B6=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 紧急修复异常bug 2. 修改处理策略 3. 每10分钟处理一次 ssh连接:超过1小时没有操作就干掉 web:超过1天的就设置完成 --- jlog/log_api.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jlog/log_api.py b/jlog/log_api.py index 43925353c..e7e43e7e6 100644 --- a/jlog/log_api.py +++ b/jlog/log_api.py @@ -15,6 +15,7 @@ from struct import unpack from subprocess import Popen from sys import platform, prefix, stderr from tempfile import NamedTemporaryFile +from jumpserver.api import logger from jinja2 import FileSystemLoader, Template from jinja2.environment import Environment @@ -86,7 +87,7 @@ def kill_invalid_connection(): for log in unfinished_logs: try: - log_file_mtime = int(os.stat(log.log_path).st_mtime) + log_file_mtime = int(os.stat('%s.log' % log.log_path).st_mtime) except OSError: log_file_mtime = 0 @@ -94,6 +95,7 @@ def kill_invalid_connection(): if log.login_type == 'ssh': try: os.kill(int(log.pid), 9) + except OSError: pass elif (now - log.start_time).days < 1: @@ -102,6 +104,7 @@ def kill_invalid_connection(): log.is_finished = True log.end_time = now log.save() + logger.warn('kill log %s' % log.log_path)