From 1bce64b713ff8f5e44603e505136d08b22160221 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Wed, 29 Oct 2014 13:38:45 +0100 Subject: [PATCH] MT#6499 pid_watcher.py: create logging file here not by run_tests.sh This fixes strange problem having empty log/pid_watcher.log file --- bin/pid_watcher.py | 18 +++++++++++++----- run_tests.sh | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/bin/pid_watcher.py b/bin/pid_watcher.py index 9335e25b..5a6bddf3 100755 --- a/bin/pid_watcher.py +++ b/bin/pid_watcher.py @@ -21,6 +21,13 @@ import sys import os.path import pyinotify +import logging +import os +BASE_DIR = "/usr/share/kamailio-config-tests" +if os.environ.has_key('BASE_DIR'): + BASE_DIR = os.environ['BASE_DIR'] +filelog = os.path.join(BASE_DIR, 'log', 'pid_watcher.log') +logging.basicConfig(filename=filelog, level=logging.DEBUG, format='%(asctime)s %(message)s') base_path = "/var/run" @@ -50,36 +57,37 @@ class Handler(pyinotify.ProcessEvent): all = True for k,v in self.watched.iteritems(): all = (all and (v['created'] or v['modified'])) - print "checking: %s[%s] all:%s" % (k,v, all) + logging.info("checking: %s[%s] all:%s" % (k,v, all)) return all def process_IN_CREATE(self, event): if watched.has_key(event.pathname): watched[event.pathname]['created'] = True - print "created %s" % event.pathname + logging.info("created %s" % event.pathname) if self.check_all(): sys.exit(0) def process_IN_IGNORED(self, event): if watched.has_key(event.pathname): watched[event.pathname]['deleted'] = True - print "deleted %s" % event.pathname + logging.info("deleted %s" % event.pathname) def process_IN_MODIFY(self, event): if watched.has_key(event.pathname): watched[event.pathname]['modified'] = True - print "modified %s" % event.pathname + logging.info("modified %s" % event.pathname) # for debug # def process_default(self, event): # if watched.has_key(event.pathname): # print event +logging.info("PID watcher started") wm = pyinotify.WatchManager() handler = Handler(watched=watched) notifier = pyinotify.Notifier(wm, default_proc_fun=handler) for service in services: service_pid = os.path.join(base_path, service) - print "Watching %s" % service_pid + logging.info("Watching %s" % service_pid) watched[service_pid] = {'deleted': False, 'created': False, 'modified': False } wm.add_watch(service_pid, pyinotify.IN_IGNORED) for d in watched_dirs: diff --git a/run_tests.sh b/run_tests.sh index 073c19ac..842bf187 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -87,7 +87,7 @@ if [ -z $SKIP ]; then echo "$(date) - Setting config debug on" ${BIN_DIR}/config_debug.pl on ${DOMAIN} if [ "${PROFILE}" == "PRO" ]; then - ( timeout 60 ${BIN_DIR}/pid_watcher.py &> ${LOG_DIR}/pid_watcher.log )& + ( timeout 60 ${BIN_DIR}/pid_watcher.py )& fi ngcpcfg apply res=$?