send shutdown on sigterm

This commit is contained in:
2017-12-11 15:06:58 -05:00
parent 973ad7dd28
commit c1334fead9
+6
View File
@@ -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()