feat: auto-recovery pyrealsense2 stuck via healthcheck + autoheal

Sostituisce il healthcheck banale (urlopen /api/health) con uno che
fallisce quando camera_open != true, e aggiunge il container willfarrell/autoheal
che restarta il backend quando Docker lo marca unhealthy. Recovery <1min
da SDK stuck senza intervento SSH.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
OliviaCandClaude Opus 4.7 committed 2026-05-25 12:15:41 +02:00
1 parent ece2171678
commit ede70a21b3
2 files changed
+414 -3

No files matched your search

+35 -3
View File
@@ -40,11 +40,43 @@ services:
condition: service_healthy
required: false
restart: unless-stopped
labels:
# autoheal monitora SOLO i container con questa label = true
autoheal: "true"
healthcheck:
test: ["CMD", "python3", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8878/api/health')"]
interval: 10s
# Healthcheck "vero": fallisce se camera_open != true.
# Usa /api/health (pubblico, no API key) che già ritorna camera_open.
# 4 retry × 15s ⇒ ~1 min di stato cattivo prima dell'autoheal restart.
test:
- CMD
- python3
- -c
- |
import urllib.request, json, sys
try:
r = urllib.request.urlopen('http://localhost:8878/api/health', timeout=3)
d = json.loads(r.read())
sys.exit(0 if d.get('data', {}).get('camera_open') else 1)
except Exception:
sys.exit(1)
interval: 15s
timeout: 5s
retries: 3
retries: 4
start_period: 30s
# -- Autoheal -------------------------------
# Monitora i container con label `autoheal=true` e li restarta automaticamente
# quando Docker li marca "unhealthy". Risolve il caso "pyrealsense2 SDK stuck".
autoheal:
image: willfarrell/autoheal:latest
container_name: autoheal-d435
restart: always
environment:
AUTOHEAL_CONTAINER_LABEL: autoheal
AUTOHEAL_INTERVAL: 10
AUTOHEAL_START_PERIOD: 30
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
# -- Frontend React Dev (hot reload) --------
frontend-dev: