From 6d66cc6cf23e975ca71c6b3b920942c7a52b5ef9 Mon Sep 17 00:00:00 2001 From: hmo Date: Sun, 19 Jul 2026 18:22:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20auto-heal=20=E2=80=94=20gateway=20down?= =?UTF-8?q?=20auto-restart=20via=20cron=20every=205min?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agents_health_check.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/agents_health_check.py b/agents_health_check.py index 232ceb53..c4c1b4ec 100644 --- a/agents_health_check.py +++ b/agents_health_check.py @@ -120,6 +120,24 @@ def run(): # ── XMPP 通道健康采集 ── _collect_xmpp_health(now) + # ── 自愈:Gateway 宕机自动重启 ── + gateway_ok = any(r["name"] == "zhiwei_gateway" and r["health"]["ok"] for r in results) + if not gateway_ok: + try: + import subprocess as _sp + _sp.run(["sudo", "-n", "pkill", "-9", "-f", "position-analyst.*gateway"], + capture_output=True, timeout=5) + _sp.run(["rm", "-f", "/home/hmo/.hermes/profiles/position-analyst/gateway.lock", + "/home/hmo/.hermes/profiles/position-analyst/gateway.pid"]) + _sp.Popen(["/home/hmo/hermes-agent/.venv/bin/python", "-m", "hermes_cli.main", + "-p", "position-analyst", "gateway", "run", "--replace"], + stdout=open("/tmp/hermes_gw_auto.log", "a"), + stderr=open("/tmp/hermes_gw_auto.log", "a"), + start_new_session=True) + print(f"[{now.strftime('%H:%M')}] Auto-heal: Gateway DOWN → restarted") + except Exception as e: + print(f"[{now.strftime('%H:%M')}] Auto-heal error: {e}") + # Handle issues if issues: with open(TODO_FILE, "a", encoding="utf-8") as f: