fix(kill invalid connection) 紧急处理超时连接

1. 紧急修复异常bug
2. 修改处理策略
3. 每10分钟处理一次
   ssh连接:超过1小时没有操作就干掉
   web:超过1天的就设置完成
pull/106/head
ibuler 2016-02-29 17:48:14 +08:00
parent 3c610668b5
commit d7bb4c1005
1 changed files with 4 additions and 1 deletions

View File

@ -15,6 +15,7 @@ from struct import unpack
from subprocess import Popen from subprocess import Popen
from sys import platform, prefix, stderr from sys import platform, prefix, stderr
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
from jumpserver.api import logger
from jinja2 import FileSystemLoader, Template from jinja2 import FileSystemLoader, Template
from jinja2.environment import Environment from jinja2.environment import Environment
@ -86,7 +87,7 @@ def kill_invalid_connection():
for log in unfinished_logs: for log in unfinished_logs:
try: 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: except OSError:
log_file_mtime = 0 log_file_mtime = 0
@ -94,6 +95,7 @@ def kill_invalid_connection():
if log.login_type == 'ssh': if log.login_type == 'ssh':
try: try:
os.kill(int(log.pid), 9) os.kill(int(log.pid), 9)
except OSError: except OSError:
pass pass
elif (now - log.start_time).days < 1: elif (now - log.start_time).days < 1:
@ -102,6 +104,7 @@ def kill_invalid_connection():
log.is_finished = True log.is_finished = True
log.end_time = now log.end_time = now
log.save() log.save()
logger.warn('kill log %s' % log.log_path)