Files
photobooth/scripts/kiosk-session.sh
Jules 3c3dbd6c8b Watchdog systemd + fix stabilité kiosk/backend
- Watchdog (30s) : vérifie backend, caméra, chromium, tue les orphelins,
  reboot auto après 10 échecs consécutifs (~5min sans service)
- kiosk-session.sh : tue les backends orphelins au démarrage, trap EXIT
  pour cleanup quand le kiosk est tué
- camera.py : force release USB avec timeout 2s quand connecter() échoue
- main.py : uvicorn.run(app) au lieu de string pour éviter double import

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-27 13:21:02 +02:00

71 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
# Verrou atomique — une seule session kiosk autorisee
exec 9>/tmp/photobooth-kiosk.lock
flock -n 9 || { echo "[kiosk] Déjà en cours, abandon."; exit 0; }
# Tuer tout backend orphelin d'une session precedente
pkill -f 'python.*backend.main' 2>/dev/null || true
sleep 1
xset s off
xset -dpms
xset s noblank
# Automount USB (pour la photostation)
udiskie --no-notify --no-appindicator &
# Liberer le DSLR : gvfsd-gphoto2 (GNOME) le monopolise sinon
pkill -f gvfsd-gphoto2 2>/dev/null || true
pkill -f gvfs-gphoto2-volume-monitor 2>/dev/null || true
# Backend en boucle : redemarre automatiquement s'il plante
_backend_loop() {
while true; do
while [ -f /tmp/photobooth-maintenance ]; do sleep 2; done
cd /home/jules/photobooth
git pull --ff-only 2>&1 | logger -t photobooth-git
source .venv/bin/activate
authbind --deep python -m backend.main 2>&1 | tee -a /tmp/photobooth-backend.log
echo "[kiosk] backend terminé, redémarrage dans 3s..."
sleep 3
done
}
_backend_loop &
BACKEND_LOOP_PID=$!
# Nettoyer le backend si le kiosk est tue
trap "kill $BACKEND_LOOP_PID 2>/dev/null; pkill -f 'python.*backend.main' 2>/dev/null" EXIT
# Attendre que le backend soit pret (max 15s)
for i in $(seq 1 15); do
curl -sf http://localhost/ > /dev/null 2>&1 && break
sleep 1
done
# Chromium en boucle : redemarre s'il plante, attend si photostation active
while true; do
while [ -f /tmp/photostation_running ]; do sleep 1; done
chromium \
--kiosk \
--noerrdialogs \
--disable-infobars \
--disable-translate \
--disable-features=TranslateUI,Translate,LockProfileCookieDatabase \
--disable-session-crashed-bubble \
--disable-component-update \
--check-for-update-interval=31536000 \
--autoplay-policy=no-user-gesture-required \
--start-fullscreen \
--user-data-dir=/home/jules/.config/chromium-kiosk \
--touch-events=enabled \
--enable-touch-drag-drop \
--force-device-scale-factor=3 \
--password-store=basic \
--lang=fr \
--remote-debugging-port=9222 \
http://localhost
echo "[kiosk] Chromium terminé, redémarrage dans 2s..."
sleep 2
done