🎉 Improved Backend Structure & Documentation 🎉
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
[Unit]
|
||||
Description=Kiosk Watchdog Service - Überwacht und startet Kiosk-Komponenten neu
|
||||
After=multi-user.target lightdm.service myp-druckerverwaltung.service
|
||||
Wants=lightdm.service myp-druckerverwaltung.service
|
||||
Description=MYP Kiosk Watchdog Service - Überwacht HTTPS Backend und Kiosk-Browser
|
||||
Documentation=https://github.com/MYP-Druckerverwaltung
|
||||
After=multi-user.target myp-https.service
|
||||
Wants=myp-https.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
@@ -10,67 +11,102 @@ Restart=always
|
||||
RestartSec=30
|
||||
ExecStart=/bin/bash -c '\
|
||||
while true; do \
|
||||
# Prüfe Backend-Service \
|
||||
if ! systemctl is-active --quiet myp-druckerverwaltung; then \
|
||||
echo "$(date): Backend-Service nicht aktiv - starte neu" >> /var/log/kiosk-watchdog.log; \
|
||||
systemctl start myp-druckerverwaltung; \
|
||||
# Prüfe HTTPS Backend-Service (Port 443) \
|
||||
if ! systemctl is-active --quiet myp-https; then \
|
||||
echo "$(date): HTTPS Backend-Service nicht aktiv - starte neu" >> /var/log/kiosk-watchdog.log; \
|
||||
systemctl start myp-https; \
|
||||
sleep 10; \
|
||||
fi; \
|
||||
\
|
||||
# Prüfe Backend-Erreichbarkeit \
|
||||
if ! curl -s --connect-timeout 5 http://localhost:5000 >/dev/null 2>&1 && ! curl -s --connect-timeout 5 http://localhost:8080 >/dev/null 2>&1; then \
|
||||
echo "$(date): Backend nicht erreichbar - starte Service neu" >> /var/log/kiosk-watchdog.log; \
|
||||
systemctl restart myp-druckerverwaltung; \
|
||||
# Prüfe HTTPS Backend-Erreichbarkeit (Port 443) \
|
||||
if ! curl -k -s --connect-timeout 5 https://localhost:443 >/dev/null 2>&1; then \
|
||||
echo "$(date): HTTPS Backend nicht erreichbar - starte Service neu" >> /var/log/kiosk-watchdog.log; \
|
||||
systemctl restart myp-https; \
|
||||
sleep 15; \
|
||||
fi; \
|
||||
\
|
||||
# Prüfe LightDM \
|
||||
if ! systemctl is-active --quiet lightdm; then \
|
||||
echo "$(date): LightDM nicht aktiv - starte neu" >> /var/log/kiosk-watchdog.log; \
|
||||
systemctl start lightdm; \
|
||||
# Prüfe SSL-Zertifikat-Gültigkeit \
|
||||
if [ -f /opt/myp/certs/localhost/localhost.crt ]; then \
|
||||
if ! openssl x509 -in /opt/myp/certs/localhost/localhost.crt -noout -checkend 86400 >/dev/null 2>&1; then \
|
||||
echo "$(date): SSL-Zertifikat läuft ab - regeneriere Zertifikat" >> /var/log/kiosk-watchdog.log; \
|
||||
python3 -c "import sys; sys.path.insert(0, \"/opt/myp\"); from utils.ssl_config import ensure_ssl_certificates; ensure_ssl_certificates(\"/opt/myp\", True)" || true; \
|
||||
systemctl restart myp-https; \
|
||||
sleep 10; \
|
||||
fi; \
|
||||
else \
|
||||
echo "$(date): SSL-Zertifikat fehlt - generiere neues Zertifikat" >> /var/log/kiosk-watchdog.log; \
|
||||
python3 -c "import sys; sys.path.insert(0, \"/opt/myp\"); from utils.ssl_config import ensure_ssl_certificates; ensure_ssl_certificates(\"/opt/myp\")" || true; \
|
||||
systemctl restart myp-https; \
|
||||
sleep 10; \
|
||||
fi; \
|
||||
\
|
||||
# Prüfe Kiosk-Benutzer Session \
|
||||
if ! pgrep -u kiosk > /dev/null; then \
|
||||
echo "$(date): Kiosk-Benutzer nicht angemeldet - starte LightDM neu" >> /var/log/kiosk-watchdog.log; \
|
||||
systemctl restart lightdm; \
|
||||
echo "$(date): Kiosk-Benutzer nicht angemeldet - prüfe Autologin" >> /var/log/kiosk-watchdog.log; \
|
||||
# Versuche getty@tty1 Service zu restarten für Autologin \
|
||||
systemctl restart getty@tty1.service; \
|
||||
sleep 15; \
|
||||
fi; \
|
||||
\
|
||||
# Prüfe Chromium Kiosk-Prozess \
|
||||
if ! pgrep -u kiosk -f "chromium.*kiosk" > /dev/null; then \
|
||||
echo "$(date): Chromium-Kiosk nicht gefunden - starte Kiosk-Session neu" >> /var/log/kiosk-watchdog.log; \
|
||||
# Versuche Kiosk-Neustart als Kiosk-Benutzer \
|
||||
sudo -u kiosk DISPLAY=:0 /home/kiosk/start-kiosk.sh & \
|
||||
if pgrep -u kiosk > /dev/null && ! pgrep -u kiosk -f "chromium.*kiosk" > /dev/null; then \
|
||||
echo "$(date): Chromium-Kiosk nicht gefunden aber Kiosk-User aktiv - starte Browser" >> /var/log/kiosk-watchdog.log; \
|
||||
# Versuche Kiosk-Service zu starten \
|
||||
systemctl --user start myp-kiosk 2>/dev/null || true; \
|
||||
sleep 10; \
|
||||
fi; \
|
||||
\
|
||||
# Prüfe X-Server \
|
||||
if ! pgrep -f "X.*:0" > /dev/null; then \
|
||||
echo "$(date): X-Server nicht gefunden - starte LightDM neu" >> /var/log/kiosk-watchdog.log; \
|
||||
systemctl restart lightdm; \
|
||||
# Prüfe X-Server für Kiosk-Display \
|
||||
if pgrep -u kiosk > /dev/null && ! pgrep -f "X.*:0" > /dev/null; then \
|
||||
echo "$(date): X-Server nicht gefunden aber Kiosk-User aktiv - starte X" >> /var/log/kiosk-watchdog.log; \
|
||||
# Versuche X-Server über Kiosk-User zu starten \
|
||||
sudo -u kiosk DISPLAY=:0 startx 2>/dev/null & \
|
||||
sleep 15; \
|
||||
fi; \
|
||||
\
|
||||
# Prüfe Display-Umgebung \
|
||||
if [ -z "$(DISPLAY=:0 xdpyinfo 2>/dev/null)" ]; then \
|
||||
echo "$(date): Display :0 nicht verfügbar - starte LightDM neu" >> /var/log/kiosk-watchdog.log; \
|
||||
systemctl restart lightdm; \
|
||||
# Prüfe Display-Verfügbarkeit \
|
||||
if pgrep -u kiosk > /dev/null && [ -z "$(DISPLAY=:0 xdpyinfo 2>/dev/null)" ]; then \
|
||||
echo "$(date): Display :0 nicht verfügbar - starte X-Session neu" >> /var/log/kiosk-watchdog.log; \
|
||||
# Beende alle X-Prozesse des Kiosk-Users und starte neu \
|
||||
pkill -u kiosk -f "X" 2>/dev/null || true; \
|
||||
sleep 5; \
|
||||
sudo -u kiosk DISPLAY=:0 startx 2>/dev/null & \
|
||||
sleep 15; \
|
||||
fi; \
|
||||
\
|
||||
# Prüfe Systemressourcen und bereinige bei Bedarf \
|
||||
MEMORY_USAGE=$(free | grep Mem | awk "{print (\$3/\$2) * 100.0}"); \
|
||||
if (( $(echo "$MEMORY_USAGE > 90" | bc -l) )); then \
|
||||
echo "$(date): Hohe Speichernutzung ($MEMORY_USAGE%) - bereinige System" >> /var/log/kiosk-watchdog.log; \
|
||||
# Bereinige Browser-Cache \
|
||||
rm -rf /home/kiosk/.chromium-kiosk/Default/Cache/* 2>/dev/null || true; \
|
||||
rm -rf /home/kiosk/.cache/* 2>/dev/null || true; \
|
||||
# Garbage Collection \
|
||||
sync; \
|
||||
echo 3 > /proc/sys/vm/drop_caches 2>/dev/null || true; \
|
||||
fi; \
|
||||
\
|
||||
# Warte 30 Sekunden vor nächster Prüfung \
|
||||
sleep 30; \
|
||||
done'
|
||||
|
||||
# Umgebungsvariablen
|
||||
# Umgebungsvariablen für HTTPS-Überwachung
|
||||
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||||
Environment=DISPLAY=:0
|
||||
Environment=PYTHONPATH=/opt/myp
|
||||
Environment=SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
|
||||
|
||||
# Logging
|
||||
StandardOutput=append:/var/log/kiosk-watchdog.log
|
||||
StandardError=append:/var/log/kiosk-watchdog.log
|
||||
|
||||
# Sicherheitseinstellungen
|
||||
NoNewPrivileges=false
|
||||
PrivateTmp=false
|
||||
ReadWritePaths=/var/log
|
||||
ReadWritePaths=/opt/myp
|
||||
ReadWritePaths=/home/kiosk
|
||||
ReadWritePaths=/proc/sys/vm
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
Reference in New Issue
Block a user