mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-25 06:42:49 +00:00
feat: 全面修改 ansible 执行方式为 receptor (#12975)
* feat: 修复 receptor kill job 的问题 * feat: 全面修改 ansible 执行方式为 receptor --------- Co-authored-by: Aaron3S <chenyang@fit2cloud.com>
This commit is contained in:
21
receptor
21
receptor
@@ -2,12 +2,15 @@
|
||||
# coding: utf-8
|
||||
|
||||
import argparse
|
||||
import shutil
|
||||
import subprocess
|
||||
import os
|
||||
import signal
|
||||
import tempfile
|
||||
|
||||
ANSIBLE_RUNNER_COMMAND = "ansible-runner"
|
||||
DEFAULT_CONTROL_SOCK_PATH = "/opt/jumpserver/data/share/control.sock"
|
||||
DEFAULT_SHARE_DIR = "data/share"
|
||||
DEFAULT_CONTROL_SOCK_PATH = os.path.join(DEFAULT_SHARE_DIR, "control.sock")
|
||||
|
||||
|
||||
class ReceptorService:
|
||||
@@ -27,7 +30,15 @@ class ReceptorService:
|
||||
'allowruntimeparams=true'
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def before_start():
|
||||
os.makedirs(os.path.join(DEFAULT_SHARE_DIR), exist_ok=True)
|
||||
status_dir = os.path.join(tempfile.gettempdir(), "receptor")
|
||||
if os.path.exists(status_dir):
|
||||
shutil.rmtree(status_dir)
|
||||
|
||||
def start(self):
|
||||
self.before_start()
|
||||
if os.path.exists(self.pid_file):
|
||||
with open(self.pid_file, 'r') as f:
|
||||
pid_str = f.read()
|
||||
@@ -47,6 +58,14 @@ class ReceptorService:
|
||||
f.write(str(process.pid))
|
||||
print("\n- Receptor service started successfully.")
|
||||
|
||||
def exit_handler(signum, frame):
|
||||
process.terminate()
|
||||
process.kill()
|
||||
|
||||
signal.signal(signal.SIGINT, exit_handler)
|
||||
signal.signal(signal.SIGTERM, exit_handler)
|
||||
process.wait()
|
||||
|
||||
def stop(self):
|
||||
if not os.path.exists(self.pid_file):
|
||||
print("\n- Receptor service is not running.")
|
||||
|
Reference in New Issue
Block a user