Debian Codegraph @

bin/watchdog.py

raw
1 """
2 A very plain watchdog for DaCHS; essentially, it checks that the PID
3 is still there.
4
5 This is mainly to help when debugging DaCHS dependencies that make the
6 thing segfault (or similar). Also systemd does the equivalent of this
7 itself, so don't bother there.
8 """
9
10 import os
11 import time
12
13 from gavo.user import serve
14
15 if os.getuid()!=0:
16 raise Exception("Only makes sense if running as root")
17
18 while True:
19 serverPID = serve.PIDManager.getPID()
20 if serverPID is None:
21 print("%s: Server found dead, starting"%time.asctime())
22 os.system("service dachs start")
23 time.sleep(10)
24
25 else:
26
27 if not os.path.exists("/proc/%s"%serverPID):
28 print("%s: Server has terminated, restarting"%(
29 time.asctime()))
30 os.system("service dachs restart")
31 time.sleep(10)
32 else:
33 time.sleep(1)