fix: auto_heal extract service_key from composite key (agent-XXX:name) for SERVICE_UNIT_MAP lookup
This commit is contained in:
@@ -146,7 +146,9 @@ def diagnose_and_heal(entry, actual_status):
|
||||
返回动作描述字符串,None 表示无操作。
|
||||
"""
|
||||
name = entry["name"]
|
||||
key = entry.get("key", "")
|
||||
raw_key = entry.get("key", "")
|
||||
# 从复合 key(如 "agent-002:hermes_gateway")提取服务名用于查表
|
||||
service_key = raw_key.split(":")[-1] if ":" in raw_key else raw_key
|
||||
host = entry.get("host", "127.0.0.1")
|
||||
check = entry.get("check", "")
|
||||
expected = entry.get("expected", "")
|
||||
@@ -166,7 +168,7 @@ def diagnose_and_heal(entry, actual_status):
|
||||
# ── 本机端口不通 → 重启服务 ──
|
||||
if check == "tcp" and port and actual != "running":
|
||||
# 尝试匹配 systemd 单元
|
||||
unit = SERVICE_UNIT_MAP.get(key)
|
||||
unit = SERVICE_UNIT_MAP.get(service_key)
|
||||
if isinstance(unit, dict):
|
||||
# 需要从 name 中提取标识("mohe", "zhiwei" 等)
|
||||
for ident, u in unit.items():
|
||||
@@ -180,8 +182,7 @@ def diagnose_and_heal(entry, actual_status):
|
||||
elif isinstance(unit, str):
|
||||
ok = systemctl_restart(unit)
|
||||
return f"restart systemd {unit}: {'OK' if ok else 'FAIL'}"
|
||||
# Docker 容器
|
||||
container = DOCKER_MAP.get(key)
|
||||
container = DOCKER_MAP.get(service_key)
|
||||
if container:
|
||||
ok = docker_restart(container)
|
||||
return f"restart docker {container}: {'OK' if ok else 'FAIL'}"
|
||||
@@ -199,7 +200,7 @@ def diagnose_and_heal(entry, actual_status):
|
||||
|
||||
# ── health_url 不通 → 重启对应服务 ──
|
||||
if check == "health_url" and actual != "running":
|
||||
container = DOCKER_MAP.get(key)
|
||||
container = DOCKER_MAP.get(service_key)
|
||||
if container:
|
||||
ok = docker_restart(container)
|
||||
return f"restart docker {container}: {'OK' if ok else 'FAIL'}"
|
||||
|
||||
Reference in New Issue
Block a user