feat: 全面修改 ansible 执行方式为 receptor (#12975)

* feat: 修复 receptor kill job  的问题

* feat: 全面修改 ansible 执行方式为 receptor

---------

Co-authored-by: Aaron3S <chenyang@fit2cloud.com>
This commit is contained in:
fit2bot
2024-04-10 11:35:38 +08:00
committed by GitHub
parent 8911c9c649
commit a8112c86e3
7 changed files with 76 additions and 31 deletions

View File

@@ -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.")