File: watchdog.py

package info (click to toggle)
gavodachs 2.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,972 kB
  • sloc: python: 100,078; xml: 3,014; javascript: 2,360; ansic: 918; sh: 216; makefile: 31
file content (33 lines) | stat: -rw-r--r-- 790 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
A very plain watchdog for DaCHS; essentially, it checks that the PID
is still there.

This is mainly to help when debugging DaCHS dependencies that make the
thing segfault (or similar).  Also systemd does the equivalent of this
itself, so don't bother there.
"""

import os
import time

from gavo.user import serve

if os.getuid()!=0:
	raise Exception("Only makes sense if running as root")

while True:
	serverPID = serve.PIDManager.getPID()
	if serverPID is None:
		print("%s: Server found dead, starting"%time.asctime())
		os.system("service dachs start")
		time.sleep(10)
	
	else:

		if not os.path.exists("/proc/%s"%serverPID):
			print("%s: Server has terminated, restarting"%(
				time.asctime()))
			os.system("service dachs restart")
			time.sleep(10)
		else:
			time.sleep(1)