diff --git a/hbc b/hbc index 1cb602a..62d2251 100755 --- a/hbc +++ b/hbc @@ -37,6 +37,9 @@ def log(msg): else: print msg +def handler(signum, frame): + if signum == signal.SIGTERM: + cleanup() class NullDevice: def write(self, s): @@ -329,6 +332,8 @@ def process(): def cleanup(): global running + if not running: + return if verbose: log('cleanup') running = False for conn in conns: @@ -538,6 +543,7 @@ if fdaemon: daemonized = True syslog.syslog(syslog.LOG_ERR, 'starting heartbeat to %s' % ','.join(hb_hosts)) +signal.signal(signal.SIGTERM, handler) running = True try: process()