Proper exit handling and don't worry about ZK state
This commit is contained in:
parent
2ae7846ccb
commit
04f5fc8f32
15
pvcd.py
15
pvcd.py
|
@ -102,21 +102,12 @@ except:
|
||||||
print('ERROR: Failed to connect to Zookeeper')
|
print('ERROR: Failed to connect to Zookeeper')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
def zk_listener(state):
|
def cleanup(signum, frame):
|
||||||
if state == kazoo.client.KazooState.LOST:
|
ansiiprint.echo('Terminating daemon', '', 'e')
|
||||||
cleanup()
|
|
||||||
elif state == kazoo.client.KazooState.SUSPENDED:
|
|
||||||
cleanup()
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
zk.add_listener(zk_listener)
|
|
||||||
|
|
||||||
def cleanup():
|
|
||||||
update_timer.shutdown()
|
|
||||||
zk.set('/nodes/{}/daemonstate'.format(myhostname), 'stop'.encode('ascii'))
|
zk.set('/nodes/{}/daemonstate'.format(myhostname), 'stop'.encode('ascii'))
|
||||||
zk.stop()
|
zk.stop()
|
||||||
zk.close()
|
zk.close()
|
||||||
|
update_timer.join()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# Handle signals gracefully
|
# Handle signals gracefully
|
||||||
|
|
Loading…
Reference in New Issue