32 lines
562 B
Python
32 lines
562 B
Python
#!/usr/bin/env python3
|
|
import os
|
|
import signal
|
|
import time
|
|
|
|
path = os.environ.get("LESAVKA_WATCHDOG_DEV", "/dev/watchdog")
|
|
interval = float(os.environ.get("LESAVKA_WATCHDOG_INTERVAL", "5"))
|
|
|
|
fd = os.open(path, os.O_WRONLY)
|
|
|
|
running = True
|
|
|
|
|
|
def handle(_sig, _frame):
|
|
global running
|
|
running = False
|
|
|
|
|
|
signal.signal(signal.SIGTERM, handle)
|
|
signal.signal(signal.SIGINT, handle)
|
|
|
|
try:
|
|
while running:
|
|
os.write(fd, b"\0")
|
|
time.sleep(interval)
|
|
finally:
|
|
try:
|
|
os.write(fd, b"V")
|
|
except Exception:
|
|
pass
|
|
os.close(fd)
|