-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwatchdog.py
More file actions
41 lines (32 loc) · 1.12 KB
/
watchdog.py
File metadata and controls
41 lines (32 loc) · 1.12 KB
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
34
35
36
37
38
39
40
41
import logging
import time
class Watchdog_Restart(Exception):
pass
class Watchdog:
def __init__(self, watched):
self.watched = watched
logger = logging.getLogger('watchdog')
logger.info("#####################")
logger.info("starting up watchdog")
logger.debug("in debug mode")
self.logger = logger
# Main loop
def watch(self):
while True:
# wait for poller.watch to be ready
is_ready = False
while not is_ready:
watch_dog = open("poller.watch", "r")
wd = watch_dog.read().strip()
is_ready = (wd == "ready")
self.logger.info("waiting for poller.watch : %s (%s)" %
(wd, is_ready))
watch_dog.close()
time.sleep(5)
try:
self.watched()
except Watchdog_Restart:
self.logger.info("watch dog was instructed to restart")
watch_dog = open("poller.watch", "w")
watch_dog.write("error")
watch_dog.close()