Proper exit handling and don't worry about ZK state

This commit is contained in:
Joshua Boniface 2018-06-16 22:47:51 -04:00
parent 2ae7846ccb
commit 04f5fc8f32
1 changed files with 3 additions and 12 deletions

15
pvcd.py
View File

@ -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