-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdoctor.py
29 lines (23 loc) · 959 Bytes
/
doctor.py
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
import os
from time import mktime, localtime, sleep
from config import load_config
# The doctor checkout the pulse file set by
# medulla. If it's been gone too long,
# according to PULSE_RATE, it kills it
# with some awkward command line fu.
settings = load_config('config/settings.yaml')
print "The doctor is in"
while True:
pulse = open(settings.sys.pulse, 'r')
lastpulse = pulse.readline()
try:
if mktime(localtime()) - float(lastpulse) > settings.sys.pulserate:
print "He's dead, Jim"
os.system("ps ax | grep 'medulla.py' | grep -v grep | awk '{print $1}' | xargs kill")
os.system("python medulla.py >> hippocampus/log/sys.log 2>>hippocampus/log/error.log &")
print "It's cool, we had the thingy"
except Exception as e:
os.system("ps ax | grep 'medulla.py' | grep -v grep | awk '{print $1}' | xargs kill")
print e
pass
sleep(settings.sys.pulserate)