Watchdog für lvl5
This commit is contained in:
33
Level/Level5/watchdog.py
Normal file
33
Level/Level5/watchdog.py
Normal 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")
|
||||||
Reference in New Issue
Block a user