Resilience : ecran pause, reconnexion WS auto, watchdog systemd, WiFi monitor

- WebSocket : reconnexion avec backoff exponentiel au lieu de reload page
- Ecran pause avec tasse de cafe quand le backend est injoignable
- Endpoint /api/health pour monitoring externe
- Watchdog systemd (sd_notify READY=1 + WATCHDOG=1 toutes les 10s)
- Service systemd durci (Type=notify, WatchdogSec=30, KillMode, limites)
- WiFi watchdog : script + timer systemd, verifie la gateway toutes les 60s
- Destinations : fallback url_tunnel (WireGuard) en priorite

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-26 19:16:39 +02:00
parent 48f54ab70a
commit 4e431507fc
10 changed files with 273 additions and 99 deletions

View File

@@ -1,15 +1,25 @@
[Unit]
Description=Photobooth
Description=Photobooth backend
After=network.target graphical.target
Wants=graphical.target
[Service]
Type=simple
Type=notify
User=jules
WorkingDirectory=/home/jules/Documents/Projet/photobooth-app
ExecStart=/home/jules/Documents/Projet/photobooth-app/scripts/start.sh
WorkingDirectory=/home/jules/photobooth
ExecStart=/home/jules/photobooth/scripts/start.sh
ExecStopPost=/bin/bash -c 'pkill -9 -f "python.*backend.main" 2>/dev/null; sleep 1'
Restart=always
RestartSec=5
RestartSec=3
WatchdogSec=30
KillMode=control-group
KillSignal=SIGTERM
TimeoutStopSec=10
StartLimitIntervalSec=120
StartLimitBurst=10
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/jules/.Xauthority
AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=graphical.target

View File

@@ -0,0 +1,6 @@
[Unit]
Description=WiFi watchdog check
[Service]
Type=oneshot
ExecStart=/home/jules/photobooth/scripts/wifi-watchdog.sh

28
scripts/wifi-watchdog.sh Normal file
View File

@@ -0,0 +1,28 @@
#!/bin/bash
# Surveille la connexion WiFi et la rétablit si elle tombe.
# Conçu pour Surface Pro (wlan0) — lancé par cron ou systemd timer.
IFACE="wlan0"
GATEWAY=$(ip route show default dev "$IFACE" 2>/dev/null | awk '{print $3}' | head -1)
LOG_TAG="wifi-watchdog"
if [ -z "$GATEWAY" ]; then
logger -t "$LOG_TAG" "Pas de gateway sur $IFACE, tentative reconnexion..."
nmcli device connect "$IFACE" 2>&1 | logger -t "$LOG_TAG"
sleep 5
GATEWAY=$(ip route show default dev "$IFACE" 2>/dev/null | awk '{print $3}' | head -1)
fi
if [ -n "$GATEWAY" ]; then
if ! ping -c 2 -W 3 -I "$IFACE" "$GATEWAY" > /dev/null 2>&1; then
logger -t "$LOG_TAG" "Ping gateway $GATEWAY echoue, reconnexion WiFi..."
nmcli device disconnect "$IFACE" 2>&1 | logger -t "$LOG_TAG"
sleep 2
nmcli device connect "$IFACE" 2>&1 | logger -t "$LOG_TAG"
sleep 5
if ! ping -c 2 -W 3 -I "$IFACE" "$GATEWAY" > /dev/null 2>&1; then
logger -t "$LOG_TAG" "Toujours pas de connexion, restart NetworkManager..."
systemctl restart NetworkManager
fi
fi
fi

View File

@@ -0,0 +1,9 @@
[Unit]
Description=WiFi watchdog - check every minute
[Timer]
OnBootSec=30
OnUnitActiveSec=60
[Install]
WantedBy=timers.target