🎉 Kiosk-Modus optimiert: Integration von Waitress für verbesserte Stabilität, IPv4-Bindung zur Vermeidung von Timeout-Problemen und automatische Bereinigung hängender Prozesse. Dokumentation aktualisiert und nicht mehr benötigte Skripte entfernt. 🛠️📈
This commit is contained in:
137
backend/app.py
137
backend/app.py
@@ -9317,12 +9317,34 @@ def get_status_color(status):
|
||||
|
||||
# ===== STARTUP UND MAIN =====
|
||||
if __name__ == "__main__":
|
||||
"""
|
||||
Start-Modi:
|
||||
-----------
|
||||
python app.py # Normal (Production Server auf 127.0.0.1:5000)
|
||||
python app.py --debug # Debug-Modus (Flask Dev Server)
|
||||
python app.py --optimized # Kiosk-Modus (Production Server + Optimierungen)
|
||||
python app.py --kiosk # Alias für --optimized
|
||||
python app.py --production # Force Production Server auch im Debug
|
||||
|
||||
Kiosk-Fix:
|
||||
- Verwendet Waitress statt Flask Dev Server (keine "unreachable" mehr)
|
||||
- Bindet nur auf IPv4 (127.0.0.1) statt IPv6 (behebt Timeout-Probleme)
|
||||
- Automatische Bereinigung hängender Prozesse
|
||||
- Performance-Optimierungen aktiviert
|
||||
"""
|
||||
import sys
|
||||
import signal
|
||||
import os
|
||||
|
||||
# Debug-Modus prüfen
|
||||
# Start-Modus prüfen
|
||||
debug_mode = len(sys.argv) > 1 and sys.argv[1] == "--debug"
|
||||
kiosk_mode = "--optimized" in sys.argv or "--kiosk" in sys.argv or os.getenv('KIOSK_MODE', '').lower() == 'true'
|
||||
|
||||
# Bei Kiosk/Optimized Modus automatisch Production-Server verwenden
|
||||
if kiosk_mode:
|
||||
os.environ['FORCE_OPTIMIZED_MODE'] = 'true'
|
||||
os.environ['USE_OPTIMIZED_CONFIG'] = 'true'
|
||||
app_logger.info("🖥️ KIOSK-MODUS ERKANNT - aktiviere Optimierungen")
|
||||
|
||||
# Windows-spezifische Umgebungsvariablen setzen für bessere Flask-Kompatibilität
|
||||
if os.name == 'nt' and debug_mode:
|
||||
@@ -9496,11 +9518,42 @@ if __name__ == "__main__":
|
||||
except Exception as e:
|
||||
app_logger.error(f"Fehler beim Starten des Schedulers: {str(e)}")
|
||||
|
||||
if debug_mode:
|
||||
# Debug-Modus: HTTP auf Port 5000
|
||||
app_logger.info("Starte Debug-Server auf 0.0.0.0:5000 (HTTP)")
|
||||
# ===== KIOSK-OPTIMIERTER SERVER-START =====
|
||||
# Verwende Waitress für Produktion (behebt "unreachable" und Performance-Probleme)
|
||||
use_production_server = not debug_mode or "--production" in sys.argv
|
||||
|
||||
# Kill hängende Prozesse auf Port 5000 (Windows-Fix)
|
||||
if os.name == 'nt' and use_production_server:
|
||||
try:
|
||||
app_logger.info("🔄 Bereinige hängende Prozesse auf Port 5000...")
|
||||
import subprocess
|
||||
result = subprocess.run(["netstat", "-ano"], capture_output=True, text=True, shell=True)
|
||||
hanging_pids = set()
|
||||
for line in result.stdout.split('\n'):
|
||||
if ":5000" in line and ("WARTEND" in line or "ESTABLISHED" in line):
|
||||
parts = line.split()
|
||||
if len(parts) >= 5 and parts[-1].isdigit():
|
||||
pid = int(parts[-1])
|
||||
if pid != 0:
|
||||
hanging_pids.add(pid)
|
||||
|
||||
for pid in hanging_pids:
|
||||
try:
|
||||
subprocess.run(["taskkill", "/F", "/PID", str(pid)],
|
||||
capture_output=True, shell=True)
|
||||
app_logger.info(f"✅ Prozess {pid} beendet")
|
||||
except:
|
||||
pass
|
||||
|
||||
if hanging_pids:
|
||||
time.sleep(2) # Kurz warten nach Cleanup
|
||||
except Exception as e:
|
||||
app_logger.warning(f"⚠️ Prozess-Cleanup fehlgeschlagen: {e}")
|
||||
|
||||
if debug_mode and "--production" not in sys.argv:
|
||||
# Debug-Modus: Flask Development Server
|
||||
app_logger.info("🔧 Starte Debug-Server auf 0.0.0.0:5000 (HTTP)")
|
||||
|
||||
# Windows-spezifische Flask-Konfiguration
|
||||
run_kwargs = {
|
||||
"host": "0.0.0.0",
|
||||
"port": 5000,
|
||||
@@ -9509,33 +9562,67 @@ if __name__ == "__main__":
|
||||
}
|
||||
|
||||
if os.name == 'nt':
|
||||
# Windows: Deaktiviere Auto-Reload um WERKZEUG_SERVER_FD Fehler zu vermeiden
|
||||
run_kwargs["use_reloader"] = False
|
||||
run_kwargs["passthrough_errors"] = False
|
||||
app_logger.info("Windows-Debug-Modus: Auto-Reload deaktiviert")
|
||||
|
||||
app.run(**run_kwargs)
|
||||
else:
|
||||
# Produktions-Modus: HTTPS auf Port 443
|
||||
ssl_context = get_ssl_context()
|
||||
|
||||
if ssl_context:
|
||||
app_logger.info("Starte HTTPS-Server auf 0.0.0.0:443")
|
||||
app.run(
|
||||
host="0.0.0.0",
|
||||
port=443,
|
||||
debug=False,
|
||||
ssl_context=ssl_context,
|
||||
threaded=True
|
||||
else:
|
||||
# Produktions-Modus: Verwende Waitress WSGI Server
|
||||
try:
|
||||
from waitress import serve
|
||||
|
||||
# IPv4-only für bessere Kompatibilität (behebt IPv6-Probleme)
|
||||
host = "127.0.0.1" # Nur IPv4!
|
||||
port = 5000
|
||||
|
||||
app_logger.info(f"🚀 Starte Production Server (Waitress) auf {host}:{port}")
|
||||
app_logger.info("💡 Kiosk-Browser sollte http://127.0.0.1:5000 verwenden")
|
||||
app_logger.info("✅ IPv6-Probleme behoben durch IPv4-only Binding")
|
||||
app_logger.info("✅ Performance optimiert für Kiosk-Betrieb")
|
||||
|
||||
# Waitress-Konfiguration für optimale Performance
|
||||
serve(
|
||||
app,
|
||||
host=host,
|
||||
port=port,
|
||||
threads=6, # Multi-threading für bessere Performance
|
||||
connection_limit=200,
|
||||
cleanup_interval=30,
|
||||
channel_timeout=120,
|
||||
log_untrusted_proxy_headers=False,
|
||||
clear_untrusted_proxy_headers=True,
|
||||
max_request_header_size=8192,
|
||||
max_request_body_size=104857600, # 100MB
|
||||
expose_tracebacks=False,
|
||||
ident="MYP-Kiosk-Server"
|
||||
)
|
||||
else:
|
||||
app_logger.info("Starte HTTP-Server auf 0.0.0.0:80")
|
||||
app.run(
|
||||
host="0.0.0.0",
|
||||
port=80,
|
||||
debug=False,
|
||||
threaded=True
|
||||
)
|
||||
|
||||
except ImportError:
|
||||
# Fallback auf Flask wenn Waitress nicht verfügbar
|
||||
app_logger.warning("⚠️ Waitress nicht installiert - verwende Flask-Server")
|
||||
app_logger.warning("💡 Installiere mit: pip install waitress")
|
||||
|
||||
ssl_context = get_ssl_context()
|
||||
|
||||
if ssl_context:
|
||||
app_logger.info("Starte HTTPS-Server auf 0.0.0.0:443")
|
||||
app.run(
|
||||
host="0.0.0.0",
|
||||
port=443,
|
||||
debug=False,
|
||||
ssl_context=ssl_context,
|
||||
threaded=True
|
||||
)
|
||||
else:
|
||||
app_logger.info("Starte HTTP-Server auf 0.0.0.0:80")
|
||||
app.run(
|
||||
host="0.0.0.0",
|
||||
port=80,
|
||||
debug=False,
|
||||
threaded=True
|
||||
)
|
||||
except KeyboardInterrupt:
|
||||
app_logger.info("🔄 Tastatur-Unterbrechung empfangen - beende Anwendung...")
|
||||
if shutdown_manager:
|
||||
|
Reference in New Issue
Block a user