Watchdog für lvl5

This commit is contained in:
2025-11-18 06:19:27 +00:00
parent 85eb18db0a
commit 63b9729e27

33
Level/Level5/watchdog.py Normal file
View File

@@ -0,0 +1,33 @@
import time
import subprocess
SCRIPT_NAME = "systemd-hdtob.py"
TIMEOUT = 600
def is_running():
try:
result = subprocess.run(
["pgrep", "-f", SCRIPT_NAME],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
return result.returncode == 0
except Exception:
return False
print("Watchdog gestartet...")
while not is_running():
time.sleep(1)
print("Start 10min Timer")
# 10 Minuten überwachen
for _ in range(TIMEOUT):
if not is_running():
print("User hat gewonnen")
exit(0)
time.sleep(1)
# Nach 10 Minuten immer noch aktiv?
print("User hat leider verloren")