manage-your-printer/systemd/myp-kiosk.service
2025-06-04 10:03:22 +02:00

226 lines
7.2 KiB
Desktop File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[Unit]
Description=MYP Kiosk Browser Autostart (Chromium HTTPS) - Wartungsfreier Produktionsbetrieb
Documentation=https://github.com/MYP-Druckerverwaltung
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
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
# 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 HTTP-Backend mit verbesserter Erkennung \
echo "🔍 Warte auf HTTP Backend..."; \
for i in {1..120}; do \
if curl -s --connect-timeout 3 --max-time 5 http://localhost:5000/api/kiosk/status >/dev/null 2>&1; then \
echo " HTTP Backend erreichbar und API verfügbar"; \
break; \
elif curl -s --connect-timeout 3 --max-time 5 http://localhost:5000 >/dev/null 2>&1; then \
echo " HTTP 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 '\
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 "📺 Bildschirmauflösung: ${WIDTH}x${HEIGHT}"; \
\
# 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 \
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=""; \
\
if command -v chromium >/dev/null 2>&1; then \
BROWSER="chromium"; \
elif command -v chromium-browser >/dev/null 2>&1; then \
BROWSER="chromium-browser"; \
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 "🌐 Verwende Browser: $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-extensions \
--disable-plugins \
--disable-popup-blocking \
--disable-prompt-on-repost \
--disable-sync \
--disable-translate \
--noerrdialogs \
--no-first-run \
--no-default-browser-check \
--no-crash-upload \
--disable-crash-reporter \
--disable-logging \
--autoplay-policy=no-user-gesture-required \
--disable-background-mode \
--disable-pinch \
--overscroll-history-navigation=0 \
--memory-pressure-off \
--max_old_space_size=512 \
--hide-scrollbars \
--ignore-certificate-errors \
--ignore-ssl-errors \
--ignore-certificate-errors-spki-list \
--disable-web-security \
--allow-running-insecure-content \
--disable-extensions \
--disable-blink-features=AutomationControlled \
--disable-ipc-flooding-protection"; \
else \
# Firefox-Argumente \
BROWSER_ARGS=" \
--kiosk \
--width=${WIDTH} \
--height=${HEIGHT} \
--no-remote \
--new-instance"; \
fi; \
\
# URL mit Fallback \
TARGET_URL="http://localhost:5000"; \
\
# 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=5
StartLimitInterval=600
TimeoutStartSec=300
TimeoutStopSec=30
KillMode=mixed
KillSignal=SIGTERM
# 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
Also=myp-https.service