🎉 Improved Blueprints for Kiosk Mode & Production Readiness 🖱️

This commit is contained in:
Till Tomczak
2025-06-20 09:19:15 +02:00
parent 0360d8c386
commit 268a270f1c
5 changed files with 34 additions and 24 deletions

View File

@ -182,10 +182,14 @@ def restart_system():
def delayed_restart():
time.sleep(2)
try:
from utils.core_system import safe_subprocess_run
if os.name == 'nt': # Windows
subprocess.run(["shutdown", "/r", "/t", "0"], check=True)
result = safe_subprocess_run(["shutdown", "/r", "/t", "0"], timeout=10)
else: # Linux/Unix
subprocess.run(["sudo", "reboot"], check=True)
result = safe_subprocess_run(["sudo", "reboot"], timeout=10)
if not result or result.returncode != 0:
kiosk_logger.error("System-Neustart-Befehl fehlgeschlagen")
except Exception as e:
kiosk_logger.error(f"Fehler beim System-Neustart: {str(e)}")

View File

@ -1,3 +1,4 @@
#!/usr/bin/env python3
"""
Production-Startskript für Mercedes-Benz TBA Marienfelde

View File

@ -329,23 +329,23 @@ class ErrorRecoverySystem:
try:
# Service-Status prüfen
result = subprocess.run(
result = safe_subprocess_run(
["systemctl", "is-active", service_name],
capture_output=True, text=True, timeout=10
capture_output=True, timeout=10
)
if result.returncode == 0:
if result and result.returncode == 0:
recovery_logger.info(f"✅ Service {service_name} ist bereits aktiv")
return True
# Service neustarten
recovery_logger.info(f"🔄 Starte Service {service_name} neu...")
result = subprocess.run(
result = safe_subprocess_run(
["systemctl", "restart", service_name],
capture_output=True, text=True, timeout=30
capture_output=True, timeout=30
)
if result.returncode == 0:
if result and result.returncode == 0:
recovery_logger.info(f"✅ Service {service_name} erfolgreich neugestartet")
# Recovery-Historie aktualisieren
@ -598,11 +598,11 @@ class WatchdogManager:
def is_service_active(self, service_name: str) -> bool:
"""Prüft ob Service aktiv ist"""
try:
result = subprocess.run(
result = safe_subprocess_run(
["systemctl", "is-active", "--quiet", service_name],
capture_output=True
capture_output=True, timeout=5
)
return result.returncode == 0
return result and result.returncode == 0
except Exception:
return False
@ -626,12 +626,12 @@ class WatchdogManager:
try:
watchdog_logger.info(f"Starte Service neu: {service_name} (Versuch {restart_count + 1}/{max_attempts})")
result = subprocess.run(
result = safe_subprocess_run(
["systemctl", "restart", service_name],
capture_output=True, text=True, timeout=30
capture_output=True, timeout=30
)
if result.returncode == 0:
if result and result.returncode == 0:
self.restart_counts[service_name] = restart_count + 1
self.last_restart_times[service_name] = now
time.sleep(self.config.get("restart_delay", 15))
@ -711,10 +711,10 @@ class WatchdogManager:
for cache_dir in cache_dirs:
if os.path.exists(cache_dir):
subprocess.run(["rm", "-rf", f"{cache_dir}/*"], shell=True)
safe_subprocess_run(["rm", "-rf", f"{cache_dir}/*"], shell=True, timeout=30)
# System-Cache leeren
subprocess.run(["sync"])
safe_subprocess_run(["sync"], timeout=10)
with open("/proc/sys/vm/drop_caches", "w") as f:
f.write("3")

View File

@ -202,6 +202,7 @@ class SafeFileHandler:
def _move_to_trash_windows(self, file_path: Path) -> bool:
"""Windows-spezifische Papierkorb-Implementation"""
try:
from utils.core_system import safe_subprocess_run
cmd = [
'powershell', '-Command',
f'Add-Type -AssemblyName Microsoft.VisualBasic; '
@ -209,13 +210,14 @@ class SafeFileHandler:
f'"OnlyErrorDialogs", "SendToRecycleBin")'
]
result = subprocess.run(cmd, capture_output=True, text=True)
result = safe_subprocess_run(cmd, capture_output=True, timeout=30)
if result.returncode == 0:
if result and result.returncode == 0:
data_logger.info(f"Datei erfolgreich in Papierkorb verschoben: {file_path}")
return True
else:
data_logger.error(f"PowerShell-Fehler: {result.stderr}")
error_msg = result.stderr if result else "Unbekannter Fehler"
data_logger.error(f"PowerShell-Fehler: {error_msg}")
return False
except Exception as e:
@ -225,6 +227,7 @@ class SafeFileHandler:
def _move_to_trash_unix(self, file_path: Path) -> bool:
"""Unix-spezifische Papierkorb-Implementation"""
try:
from utils.core_system import safe_subprocess_run
tools = ['gio', 'gvfs-trash', 'trash-put']
for tool in tools:
@ -236,9 +239,9 @@ class SafeFileHandler:
elif tool == 'trash-put':
cmd = ['trash-put', str(file_path)]
result = subprocess.run(cmd, capture_output=True, text=True)
result = safe_subprocess_run(cmd, capture_output=True, timeout=10)
if result.returncode == 0:
if result and result.returncode == 0:
data_logger.info(f"Datei erfolgreich in Papierkorb verschoben ({tool}): {file_path}")
return True

View File

@ -40,13 +40,15 @@ class SSLManager:
]
# Führe OpenSSL-Befehl aus
result = subprocess.run(cmd, capture_output=True, text=True)
from utils.core_system import safe_subprocess_run
result = safe_subprocess_run(cmd, capture_output=True, timeout=30)
if result.returncode == 0:
if result and result.returncode == 0:
logger.info(f"✅ SSL-Zertifikat erfolgreich erstellt: {self.cert_path}")
return True
else:
logger.error(f"❌ Fehler beim Erstellen des SSL-Zertifikats: {result.stderr}")
error_msg = result.stderr if result else "Unbekannter Fehler"
logger.error(f"❌ Fehler beim Erstellen des SSL-Zertifikats: {error_msg}")
return False
except FileNotFoundError: