refactor(api): move /health into app_system router
This commit is contained in:
+2
-31
@@ -5,6 +5,7 @@ from app_files import init_files_router
|
||||
from app_pods import init_pods_router
|
||||
from app_containers import init_containers_router, start_stats_poller
|
||||
from app_networks import init_networks_router
|
||||
from app_system import init_system_router
|
||||
from fastapi import FastAPI, HTTPException
|
||||
import requests_unixsocket
|
||||
from common import (
|
||||
@@ -29,39 +30,9 @@ 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}}
|
||||
|
||||
|
||||
# --- ROUTERS ---
|
||||
# Images API lives in dedicated modules to keep this file from growing further.
|
||||
app.include_router(init_system_router(SESSION, PODMAN_API_BASE))
|
||||
app.include_router(init_images_router(SESSION, PODMAN_API_BASE))
|
||||
app.include_router(init_files_router(SESSION, PODMAN_API_BASE, WORKLOADS_DIR))
|
||||
app.include_router(init_networks_router(SESSION, PODMAN_API_BASE))
|
||||
|
||||
Reference in New Issue
Block a user