🎉 Refactor and optimize database files, enhance error handling with new utility scripts 📚, and update documentation on fault tolerance and unattended operation. 🚀

This commit is contained in:
2025-06-02 14:57:58 +02:00
parent 7bea427bd6
commit 6ff407a895
29 changed files with 3148 additions and 450 deletions

View File

@ -1,9 +1,11 @@
[Unit]
Description=MYP Kiosk Browser Autostart (Chromium HTTPS)
Description=MYP Kiosk Browser Autostart (Chromium HTTPS) - Wartungsfreier Produktionsbetrieb
Documentation=https://github.com/MYP-Druckerverwaltung
After=graphical-session.target myp-https.service
Wants=myp-https.service
After=graphical-session.target myp-https.service network-online.target
Wants=myp-https.service network-online.target
Requires=graphical-session.target
StartLimitBurst=5
StartLimitInterval=600
[Service]
Type=simple
@ -11,45 +13,118 @@ User=kiosk
Group=kiosk
Environment=DISPLAY=:0
Environment=XAUTHORITY=/home/kiosk/.Xauthority
Environment=HOME=/home/kiosk
Environment=XDG_RUNTIME_DIR=/run/user/1001
Environment=WAYLAND_DISPLAY=
Environment=GDK_BACKEND=x11
WorkingDirectory=/home/kiosk
# Warte auf HTTPS-Backend und starte dann Chromium
ExecStartPre=/bin/bash -c 'echo "Warte auf HTTPS Backend..."; for i in {1..60}; do if curl -k -s https://localhost:443 >/dev/null 2>&1; then echo "HTTPS Backend erreichbar"; break; fi; echo "Warte... ($i/60)"; sleep 2; done'
# Robuste Backend-Wartung mit verbesserter Fehlererkennung
ExecStartPre=/bin/bash -c '\
echo "=== MYP Kiosk-Service startet $(date) ==="; \
\
# Prüfe ob X11 läuft \
for i in {1..30}; do \
if DISPLAY=:0 xset q >/dev/null 2>&1; then \
echo "✅ X11 Display verfügbar"; \
break; \
fi; \
echo "⏳ Warte auf X11 Display... ($i/30)"; \
sleep 2; \
done; \
\
# Warte auf HTTPS-Backend mit verbesserter Erkennung \
echo "🔍 Warte auf HTTPS Backend..."; \
for i in {1..120}; do \
if curl -k -s --connect-timeout 3 --max-time 5 https://localhost:443/api/kiosk/status >/dev/null 2>&1; then \
echo "✅ HTTPS Backend erreichbar und API verfügbar"; \
break; \
elif curl -k -s --connect-timeout 3 --max-time 5 https://localhost:443 >/dev/null 2>&1; then \
echo "✅ HTTPS Backend erreichbar"; \
break; \
fi; \
echo "⏳ Warte auf Backend... ($i/120)"; \
sleep 3; \
done; \
\
# Räume alte Browser-Prozesse auf \
pkill -f "chromium.*kiosk" 2>/dev/null || true; \
pkill -f "firefox.*kiosk" 2>/dev/null || true; \
sleep 2; \
'
# Robuster Kiosk-Start mit Fehlerresilienz
ExecStart=/bin/bash -c '\
# Bildschirmauflösung ermitteln \
RESOLUTION=$(DISPLAY=:0 xrandr 2>/dev/null | grep "*" | head -1 | awk "{print \$1}" || echo "1920x1080"); \
set -e; \
\
# Logging-Setup \
LOG_FILE="/var/log/myp-kiosk.log"; \
exec 1> >(tee -a "$LOG_FILE"); \
exec 2>&1; \
\
echo "🚀 Starte Kiosk-Modus $(date)"; \
\
# Bildschirmauflösung robust ermitteln \
RESOLUTION=$(DISPLAY=:0 xrandr 2>/dev/null | grep -E "\*|\+" | head -1 | awk "{print \$1}" || echo "1920x1080"); \
WIDTH=$(echo $RESOLUTION | cut -d"x" -f1); \
HEIGHT=$(echo $RESOLUTION | cut -d"x" -f2); \
echo "Erkannte Auflösung: ${WIDTH}x${HEIGHT}"; \
echo "📺 Bildschirmauflösung: ${WIDTH}x${HEIGHT}"; \
\
# Bildschirmschoner deaktivieren \
DISPLAY=:0 xset s off; \
DISPLAY=:0 xset s noblank; \
DISPLAY=:0 xset -dpms; \
# Display-Konfiguration optimieren \
DISPLAY=:0 xset s off 2>/dev/null || true; \
DISPLAY=:0 xset s noblank 2>/dev/null || true; \
DISPLAY=:0 xset -dpms 2>/dev/null || true; \
DISPLAY=:0 xset r rate 250 30 2>/dev/null || true; \
echo "⚙️ Display-Energieverwaltung deaktiviert"; \
\
# Mauszeiger verstecken \
DISPLAY=:0 unclutter -idle 0.1 -root -noevents & \
if command -v unclutter >/dev/null 2>&1; then \
DISPLAY=:0 unclutter -idle 0.5 -root -noevents & \
echo "🖱️ Mauszeiger-Versteckung aktiviert"; \
fi; \
\
# Browser-Auswahl mit Prioritäten \
BROWSER=""; \
BROWSER_ARGS=""; \
\
# Chromium Kiosk-Modus starten \
if command -v chromium >/dev/null 2>&1; then \
BROWSER="chromium"; \
elif command -v chromium-browser >/dev/null 2>&1; then \
BROWSER="chromium-browser"; \
else \
echo "Kein Chromium gefunden - verwende Firefox"; \
elif command -v google-chrome >/dev/null 2>&1; then \
BROWSER="google-chrome"; \
elif command -v firefox-esr >/dev/null 2>&1; then \
BROWSER="firefox-esr"; \
elif command -v firefox >/dev/null 2>&1; then \
BROWSER="firefox"; \
else \
echo "❌ Kein unterstützter Browser gefunden"; \
exit 1; \
fi; \
\
echo "Starte $BROWSER im Kiosk-Modus..."; \
echo "🌐 Verwende Browser: $BROWSER"; \
\
if [[ "$BROWSER" == "chromium"* ]]; then \
exec $BROWSER \
# Browser-spezifische Argumente \
if [[ "$BROWSER" == "chromium"* ]] || [[ "$BROWSER" == "google-chrome"* ]]; then \
BROWSER_ARGS=" \
--kiosk \
--no-sandbox \
--disable-dev-shm-usage \
--disable-gpu-sandbox \
--disable-software-rasterizer \
--disable-background-timer-throttling \
--disable-backgrounding-occluded-windows \
--disable-renderer-backgrounding \
--disable-field-trial-config \
--disable-features=TranslateUI,VizDisplayCompositor,AudioServiceOutOfProcess \
--enable-features=OverlayScrollbar,VaapiVideoDecoder \
--force-device-scale-factor=1.0 \
--window-size=${WIDTH},${HEIGHT} \
--window-position=0,0 \
--user-data-dir=/home/kiosk/.chromium-kiosk \
--disable-infobars \
--disable-session-crashed-bubble \
--disable-restore-session-state \
--disable-features=TranslateUI \
--disable-extensions \
--disable-plugins \
--disable-popup-blocking \
@ -59,24 +134,15 @@ ExecStart=/bin/bash -c '\
--noerrdialogs \
--no-first-run \
--no-default-browser-check \
--no-crash-upload \
--disable-crash-reporter \
--disable-logging \
--autoplay-policy=no-user-gesture-required \
--start-fullscreen \
--start-maximized \
--window-size=${WIDTH},${HEIGHT} \
--window-position=0,0 \
--user-data-dir=/home/kiosk/.chromium-kiosk \
--disable-background-mode \
--force-device-scale-factor=1.0 \
--disable-pinch \
--overscroll-history-navigation=0 \
--disable-dev-shm-usage \
--memory-pressure-off \
--max_old_space_size=512 \
--disable-background-timer-throttling \
--disable-backgrounding-occluded-windows \
--disable-renderer-backgrounding \
--disable-features=VizDisplayCompositor \
--enable-features=OverlayScrollbar \
--hide-scrollbars \
--ignore-certificate-errors \
--ignore-ssl-errors \
@ -84,24 +150,77 @@ ExecStart=/bin/bash -c '\
--disable-web-security \
--allow-running-insecure-content \
--unsafely-treat-insecure-origin-as-secure=https://localhost:443 \
https://localhost:443; \
--disable-blink-features=AutomationControlled \
--disable-ipc-flooding-protection"; \
else \
exec firefox-esr \
# Firefox-Argumente \
BROWSER_ARGS=" \
--kiosk \
--width=${WIDTH} \
--height=${HEIGHT} \
https://localhost:443; \
fi'
--no-remote \
--new-instance"; \
fi; \
\
# URL mit Fallback \
TARGET_URL="https://localhost:443"; \
\
# Browser starten mit Fehlerbehandlung \
echo "🖥️ Starte $BROWSER im Kiosk-Modus..."; \
echo "🔗 URL: $TARGET_URL"; \
\
# Umgebungsvariablen setzen \
export DISPLAY=:0; \
export HOME=/home/kiosk; \
export XDG_RUNTIME_DIR=/run/user/1001; \
export LIBGL_ALWAYS_SOFTWARE=1; \
export MOZ_DISABLE_RDD_SANDBOX=1; \
export MOZ_DISABLE_CONTENT_SANDBOX=1; \
\
# Browser-Start mit exec für korrekte Signal-Behandlung \
exec $BROWSER $BROWSER_ARGS "$TARGET_URL" 2>&1; \
'
# Robuste Restart-Konfiguration für wartungsfreien Betrieb
Restart=always
RestartSec=15
StartLimitBurst=3
StartLimitInterval=300
StartLimitBurst=5
StartLimitInterval=600
TimeoutStartSec=300
TimeoutStopSec=30
KillMode=mixed
KillSignal=SIGTERM
# Logging
# Ressourcen-Management für Stabilität
LimitNOFILE=65536
LimitNPROC=4096
MemoryHigh=1G
MemoryMax=1.5G
CPUQuota=80%
# Erweiterte Service-Überwachung
WatchdogSec=60
NotifyAccess=all
# Fehlerresilienz-Features
PrivateNetwork=false
PrivateTmp=true
ProtectHome=false
ProtectSystem=strict
ReadWritePaths=/home/kiosk /var/log /tmp
NoNewPrivileges=false
# Logging-Konfiguration
StandardOutput=journal
StandardError=journal
SyslogIdentifier=myp-kiosk
LogRateLimitBurst=1000
LogRateLimitIntervalSec=30
# Service-Abhängigkeiten für robuste Startsequenz
Requisite=myp-https.service
BindsTo=graphical-session.target
[Install]
WantedBy=graphical-session.target
WantedBy=graphical-session.target
Also=myp-https.service