From c1334fead9c71ab7775b352e12f0bfaea458da2c Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Mon, 11 Dec 2017 15:06:58 -0500 Subject: [PATCH] send shutdown on sigterm --- hbc | 6 ++++++ 1 file changed, 6 insertions(+) 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()