Files
mindnet/deploy/healthcheck.py
T
LarsandClaude Opus 5.5 347ca50e71
Deploy mindnet DEV (Container) / deploy (push) Successful in 50s
Container: Vault-Prüfung ohne festen Dateiaufbau (wie systemd)
Der Preflight verlangte _system/dictionary/edge_vocabulary.md, die es nur
im NAS-Vault gibt. Der Dev-Vault vault_master ist anders aufgebaut, systemd
prüft nichts davon. Jetzt: Vault muss lesbar und nicht leer sein; eine
bestimmte Datei nur noch optional über MINDNET_VAULT_SENTINEL. Default für
MINDNET_VAULT_ROOT wie in app/config.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 21:47:24 +01:00

45 lines
1.4 KiB
Python

"""
FILE: deploy/healthcheck.py
DESCRIPTION: Docker-Healthcheck für API und UI.
API ist nur gesund, wenn /healthz antwortet UND der Vault-Sentinel
lesbar ist. Ein zur Laufzeit ausgefallenes NAS wird so als
'unhealthy' sichtbar, statt still auf einem leeren Mountpunkt zu laufen.
USAGE: healthcheck.py api | ui
"""
from __future__ import annotations
import os
import sys
import urllib.request
from pathlib import Path
URLS = {
"api": "http://127.0.0.1:8000/healthz",
"ui": "http://127.0.0.1:8501/_stcore/health",
}
def main(mode: str) -> int:
try:
with urllib.request.urlopen(URLS[mode], timeout=5) as res:
if res.status != 200:
return 1
except Exception as e:
print(f"health: {mode} nicht erreichbar ({type(e).__name__})")
return 1
if mode == "api" and os.getenv("MINDNET_VAULT_REQUIRED", "true").lower() == "true":
root = Path(os.getenv("MINDNET_VAULT_ROOT") or "./vault_master")
sentinel_name = os.getenv("MINDNET_VAULT_SENTINEL", "").strip()
try:
ok = (root / sentinel_name).is_file() if sentinel_name else next(root.iterdir(), None) is not None
except OSError:
ok = False
if not ok:
print(f"health: Vault leer oder nicht lesbar ({root})")
return 1
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1] if len(sys.argv) > 1 else "api"))