refactor(api): move /health into app_system router

This commit is contained in:
kodi
2026-02-28 10:51:22 +01:00
parent 492edc2ec0
commit e61f2ccf76
3 changed files with 46 additions and 31 deletions
+43
View File
@@ -0,0 +1,43 @@
import subprocess
from fastapi import APIRouter
def init_system_router(session, podman_api_base: str) -> APIRouter:
router = APIRouter(tags=["system"])
@router.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},
}
return router