From c0ca2a161852824d2de2dfb3ead99847530e704e Mon Sep 17 00:00:00 2001 From: lework Date: Sun, 23 Feb 2020 21:17:52 +0800 Subject: [PATCH] add --- python/supervisor_healthCheck.py | 40 ++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/python/supervisor_healthCheck.py b/python/supervisor_healthCheck.py index eda956e..bc07f2a 100644 --- a/python/supervisor_healthCheck.py +++ b/python/supervisor_healthCheck.py @@ -262,7 +262,6 @@ class HealthCheck(object): initialDelaySeconds = config.get('initialDelaySeconds', self.initialDelaySeconds) sendResolved = config.get('sendResolved', self.sendResolved) action_type = config.get('action', 'restart') - action_exec_cmd = config.get('execCmd') check_type = config.get('type', 'HTTP').lower() check_method = self.http_check @@ -324,10 +323,10 @@ class HealthCheck(object): check_state[program]['failure'] != 0 and check_state[program]['failure'] % ( (periodSeconds + initialDelaySeconds) * 2) == 0): action_param = { + 'config': config, 'action_type': action_type, 'check_status': check_status, - 'msg': check_result.get('msg', ''), - 'action_exec_cmd': action_exec_cmd + 'msg': check_result.get('msg', '') } self.action(program, **action_param) check_state[program]['action'] = True @@ -485,9 +484,9 @@ class HealthCheck(object): """ action_type = args.get('action_type') msg = args.get('msg') - action_exec_cmd = args.get('action_exec_cmd') check_status = args.get('check_status') - + config = args.get('config') + self.log(program, 'Action: %s', action_type) action_list = action_type.split(',') @@ -495,8 +494,15 @@ class HealthCheck(object): restart_result = self.action_supervisor_restart(program) msg += '\r\n Restart:%s' % restart_result elif 'exec' in action_list: + action_exec_cmd = config.get('action_exec_cmd') exec_result = self.action_exec(program, action_exec_cmd) msg += '\r\n Exec:%s' % exec_result + elif 'kill' in action_list: + pid_get = config.get('pidGet', 'supervisor') + pid_file = config.get('pidFile', ) + pid, err = self.get_pid(program, pid_get, pid_file) + kill_result = self.action_kill(program, pid) + msg += '\r\n Kill:%s' % kill_result if 'email' in action_list and self.mail_config: self.action_email(program, action_type, msg, check_status) @@ -563,6 +569,30 @@ class HealthCheck(object): self.log(program, "Action: exec result %s", result) return result + + def action_kill(self, program, pid): + """ + 杀死进程 + :param program: + :param pid: + :return: + """ + self.log(program, 'Action: kill') + result = 'success' + + if int(pid) < 3: + return 'Failed to kill %s, pid: %s '% (program, exitcode) + + cmd = "kill -9 %s" % pid + exitcode, stdout, stderr = shell(cmd) + + if exitcode == 0: + self.log(program, "Action: kill result success") + else: + result = 'Failed to kill %s, pid: %s exiting: %s' % (program, pid, exitcode) + self.log(program, "Action: kill result %s", result) + + return result def action_email(self, program, action_type, msg, check_status): """