"""Container healthcheck. `python -m app_healthcheck` from ai-compose.yml. Exits 0 only if the process answers /healthz. It deliberately does not check Cube or imh - an unreachable upstream is a degraded API, not a dead container, and flapping the container makes that harder to diagnose, not easier. """ import sys import urllib.request try: with urllib.request.urlopen("http://localhost:8000/healthz", timeout=4) as r: sys.exit(0 if r.status == 200 else 1) except Exception: sys.exit(1)