feat(api): Codex: add /health endpoint with podman + systemd checks
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user