From ac2b3c464cff4643b1078b02c7024bc1d15e2a6c Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Mon, 25 Jun 2018 23:12:56 -0400 Subject: [PATCH] [#3] Add some correction to handle this properly --- pvcd.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pvcd.py b/pvcd.py index 9caad55b..1084a2f0 100755 --- a/pvcd.py +++ b/pvcd.py @@ -142,7 +142,7 @@ def zk_listener(state): zk_conn.add_listener(zk_listener) # Cleanup function -def cleanup(signum, frame): +def cleanup(): ansiiprint.echo('Terminating daemon', '', 'e') # Set stop state in Zookeeper zk_conn.set('/nodes/{}/daemonstate'.format(myhostname), 'stop'.encode('ascii')) @@ -150,8 +150,6 @@ def cleanup(signum, frame): zk_conn.close() # Stop keepalive thread stopKeepaliveTimer(update_timer) - # Exit - sys.exit(0) # Flush function def flush(): @@ -159,15 +157,18 @@ def flush(): this_node.flush() # Shutdown function -def dshutdown(): +def dshutdown(signum, frame): ansiiprint.echo('Flushing this node', '', 'e') flush() ansiiprint.echo('NOTE: This node must be unflushed by the administrator after daemon startup', '', 'i') cleanup() + sys.exit(0) # Reload shutdown function -def dreload(): +def dreload(signum, frame): cleanup() + python = sys.executable + os.execl(python, python, *sys.argv) # Handle signals gracefully signal.signal(signal.SIGTERM, dshutdown)