TT#4475 pid_watcher.py: catch SIGTERM and log that the process was aborted

Change-Id: Ic97859a8b6d83665125e376ce80573bfcd4a65d1
changes/29/8729/1
Victor Seva 10 years ago
parent af1467a751
commit e3934987d1

@ -24,6 +24,7 @@ import os.path
import pyinotify
import sys
import argparse
import signal
BASE_DIR = "/usr/share/kamailio-config-tests"
if 'BASE_DIR' in os.environ:
@ -53,11 +54,20 @@ watched_dirs = [
watched = {}
def sigterm_handler(_signo, _stack_frame):
logging.info("Process aborted")
sys.exit(2)
class Handler(pyinotify.ProcessEvent):
def my_init(self, watched):
self.watched = watched
def check_done(self):
logging.info("All OK, done")
sys.exit(0)
def check_all(self):
all = True
for k, v in self.watched.iteritems():
@ -70,7 +80,7 @@ class Handler(pyinotify.ProcessEvent):
watched[event.pathname]['created'] = True
logging.info("created %s" % event.pathname)
if self.check_all():
sys.exit(0)
self.check_done()
def process_IN_IGNORED(self, event):
if event.pathname in watched:
@ -82,12 +92,15 @@ class Handler(pyinotify.ProcessEvent):
watched[event.pathname]['modified'] = True
logging.info("modified %s" % event.pathname)
if self.check_all():
sys.exit(0)
self.check_done()
# for debug
# def process_default(self, event):
# if watched.has_key(event.pathname):
# print event
# catch SIGTERM signal
signal.signal(signal.SIGTERM, sigterm_handler)
parser = argparse.ArgumentParser(
description='watch some pids to detect restarts')
parser.add_argument('--pbx', dest='pbx', action='store_true',
@ -118,4 +131,5 @@ for service in services:
for d in watched_dirs:
wm.add_watch(d, pyinotify.ALL_EVENTS)
logging.info("start loop")
notifier.loop()

Loading…
Cancel
Save