44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
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
|