mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-26 07:22:27 +00:00
feat: 优化代码结构,receptor开关,修改为 tcp 通信 (#13078)
* feat: 优化代码结构,receptor开关,修改为 tcp 通信 * fix: 修改导包路径 * fix: 修复错别字 * fix: 修改导包路径 * perf: 优化代码 * fix: 修复任务不执行的问题 * perf: 优化配置项名称 * perf: 优化代码结构 * perf: 优化代码 --------- Co-authored-by: Aaron3S <chenyang@fit2cloud.com>
This commit is contained in:
30
receptor
30
receptor
@@ -9,8 +9,7 @@ import os
|
||||
import signal
|
||||
import tempfile
|
||||
|
||||
import psutil
|
||||
from psutil import NoSuchProcess
|
||||
from apps.libs.process.ssh import kill_ansible_ssh_process
|
||||
|
||||
ANSIBLE_RUNNER_COMMAND = "ansible-runner"
|
||||
|
||||
@@ -22,6 +21,8 @@ DEFAULT_SHARE_DIR = os.path.join(PROJECT_DIR, "data", "share")
|
||||
DEFAULT_ANSIBLE_MODULES_DIR = os.path.join(APPS_DIR, "libs", "ansible", "modules")
|
||||
DEFAULT_CONTROL_SOCK_PATH = os.path.join(DEFAULT_SHARE_DIR, "control.sock")
|
||||
|
||||
DEFAULT_TCP_LISTEN_ADDRESS = "0.0.0.0:7521"
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
os.chdir(APPS_DIR)
|
||||
@@ -34,9 +35,10 @@ class ReceptorService:
|
||||
'receptor',
|
||||
'--local-only',
|
||||
'--node', 'id=primary',
|
||||
'--log-level', 'level=Error',
|
||||
'--control-service',
|
||||
'service=control',
|
||||
'filename={}'.format(DEFAULT_CONTROL_SOCK_PATH),
|
||||
'tcplisten={}'.format(DEFAULT_TCP_LISTEN_ADDRESS),
|
||||
'--work-command',
|
||||
'worktype={}'.format(ANSIBLE_RUNNER_COMMAND),
|
||||
'command={}'.format(ANSIBLE_RUNNER_COMMAND),
|
||||
@@ -49,6 +51,7 @@ class ReceptorService:
|
||||
'allowruntimeparams=true'
|
||||
]
|
||||
|
||||
|
||||
@staticmethod
|
||||
def before_start():
|
||||
os.makedirs(os.path.join(DEFAULT_SHARE_DIR), exist_ok=True)
|
||||
@@ -141,29 +144,12 @@ def kill_progress_tree(pid=None):
|
||||
try:
|
||||
pid_input = input()
|
||||
pid = int(pid_input)
|
||||
logger.info("progress {} will be kill".format(pid))
|
||||
kill_ansible_ssh_process(pid)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
return
|
||||
|
||||
logger.info("progress {} will be kill".format(pid))
|
||||
|
||||
try:
|
||||
current_process = psutil.Process(pid)
|
||||
except NoSuchProcess as e:
|
||||
logger.error(e)
|
||||
return
|
||||
|
||||
children = current_process.children(recursive=True)
|
||||
for child in children:
|
||||
if child.pid == 1:
|
||||
continue
|
||||
if child.name() != 'ssh':
|
||||
continue
|
||||
try:
|
||||
child.kill()
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(
|
||||
|
Reference in New Issue
Block a user