def try_to_kill_process_exist(self): """ Try to kill process, if already exist """ script_path = os.path.realpath( os.path.join(self.install_path, Constant.ANORMALY_MAIN_SCRIPT)) process_list = [ (cmd % (Constant.CMD_PREFIX, os.path.dirname(script_path), script_path)).split(self.version)[-1] for cmd in self.service_list ] for process in process_list: process_num = CommonTools.check_process(process) if process_num: CommonTools.grep_process_and_kill(process) g.logger.info('Killed process of [%s]' % process)
def stop_agent_server_monitor(self): """ Stop process of agent, server and monitor, if failed, try to kill it. """ script_path = os.path.realpath( os.path.join(self.install_path, Constant.ANORMALY_MAIN_SCRIPT)) if not os.path.isfile(script_path): raise Exception(Errors.FILE_DIR_PATH['gauss_0102'] % script_path + 'Please confirm your files are integrated') for cmd in self.stopping_list: stop_cmd = cmd % (Constant.CMD_PREFIX, os.path.dirname(script_path), script_path) status, output = subprocess.getstatusoutput(stop_cmd) if status != 0: target = stop_cmd.replace('stop', 'start').split(self.install_version)[-1] g.logger.warning('Failed stop process,command[%s],error[%s]' % (stop_cmd, output)) stat, out = CommonTools.grep_process_and_kill(target) if stat != 0: g.logger.error('Failed kill process [%s] ' 'with error [%s], please manually stop it.' % (target, out)) else: g.logger.info('Successfully kill process [%s].' % target) else: g.logger.info('Successfully stop process with command:[%s]' % stop_cmd)