feat(api): Codex: add /health endpoint with podman + systemd checks

This commit is contained in:
kodi
2026-02-25 13:16:53 +01:00
parent ebb6d755a0
commit b89a31a068
7 changed files with 536 additions and 0 deletions
+30
View File
@@ -52,6 +52,36 @@ def _run_systemctl_action(action: str, unit: str):
cmd = ["systemctl", "--user", action, unit]
return _systemctl(cmd)
@app.get("/health")
def health():
podman_ok = False
try:
r = SESSION.get(f"{PODMAN_API_BASE}/libpod/info", timeout=2)
if r.status_code == 200:
try:
r.json()
podman_ok = True
except Exception:
podman_ok = False
except Exception:
podman_ok = False
systemd_reachable = False
try:
res = subprocess.run(
["systemctl", "--user", "list-units", "--no-pager", "--no-legend"],
capture_output=True,
text=True,
check=False,
timeout=2,
)
systemd_reachable = (res.returncode == 0)
except Exception:
systemd_reachable = False
ok = podman_ok and systemd_reachable
return {"ok": ok, "podman": {"ok": podman_ok}, "systemd_user": {"reachable": systemd_reachable}}
# --- MODELS ---
class FileContent(BaseModel):