fix: dispatch detect start to mainland nodes

This commit is contained in:
Your Name
2026-04-19 02:18:42 +08:00
parent b9c29481b5
commit 1adfeed1ab
6 changed files with 297 additions and 5 deletions

View File

@@ -25,6 +25,9 @@ _SSH_REMOTE_TIMEOUT_SECONDS = {
"diagnostics.collect": 90,
"runtime.start_worker": 45,
"runtime.stop_worker": 45,
"runtime.start_detection": 45,
"runtime.stop_detection": 45,
"runtime.pull_tasks": 60,
"runtime.restart_api": 45,
"runtime.start_sync_agent": 45,
"runtime.stop_sync_agent": 45,
@@ -231,6 +234,18 @@ def candidate_runtime_logs_dirs():
return dirs
def runtime_module_roots():
roots = []
for candidate in (
Path.cwd() / "domain-api",
Path("/opt/domaincheck/domain-api"),
Path("/www/wwwroot/getDomain/domain-api"),
):
if candidate not in roots:
roots.append(candidate)
return roots
def service_log_file_candidates(service_name):
normalized_service_name = str(service_name or "").strip()
if not normalized_service_name:
@@ -297,6 +312,29 @@ def systemctl_action_name(action):
return ""
def execute_runtime_action(action, payload):
runtime_action_name = str(action or "").strip().split(".", 1)[-1]
for root in runtime_module_roots():
app_dir = root / "app"
if not app_dir.exists():
continue
root_text = str(root)
if root_text not in sys.path:
sys.path.insert(0, root_text)
try:
from app.services.runtime_control_service import runtime_action
except Exception:
continue
ok, message, result = runtime_action(runtime_action_name, dict(payload or {{}}))
normalized_result = dict(result or {{}})
normalized_result["runtime_action"] = runtime_action_name
normalized_result["payload"] = dict(payload or {{}})
normalized_result["executor"] = "ssh"
normalized_result["runtime_root"] = root_text
return ok, message, normalized_result
return False, f"runtime action import failed: {{runtime_action_name}}", {{"action": action, "executor": "ssh"}}
def execute(action, payload):
if action == "health.snapshot":
checks = {{}}
@@ -320,6 +358,9 @@ def execute(action, payload):
}}
return int(code or 0) == 0, stdout or stderr or f"{{service_name}} status collected", result
if action in ("runtime.start_detection", "runtime.stop_detection", "runtime.pull_tasks"):
return execute_runtime_action(action, payload)
systemctl_action = systemctl_action_name(action)
if systemctl_action:
service_name = service_name_for_action(action, payload)