feat: auto-heal — gateway down auto-restart via cron every 5min
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user