From 04f5fc8f32ca8353ab9f877f0bf91521395b57b9 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sat, 16 Jun 2018 22:47:51 -0400 Subject: [PATCH] Proper exit handling and don't worry about ZK state --- pvcd.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/pvcd.py b/pvcd.py index 7cff3e82..867b7d63 100755 --- a/pvcd.py +++ b/pvcd.py @@ -102,21 +102,12 @@ except: print('ERROR: Failed to connect to Zookeeper') exit(1) -def zk_listener(state): - if state == kazoo.client.KazooState.LOST: - cleanup() - elif state == kazoo.client.KazooState.SUSPENDED: - cleanup() - else: - pass - -zk.add_listener(zk_listener) - -def cleanup(): - update_timer.shutdown() +def cleanup(signum, frame): + ansiiprint.echo('Terminating daemon', '', 'e') zk.set('/nodes/{}/daemonstate'.format(myhostname), 'stop'.encode('ascii')) zk.stop() zk.close() + update_timer.join() sys.exit(0) # Handle signals gracefully