Wait for server to become avaliable

This commit is contained in:
Philip Trauner 2017-04-24 14:25:17 +03:00
parent fc95b26c45
commit 11a4c760d7

View file

@ -347,14 +347,20 @@ except (IOError, ExceptionInConfigError):
try:
ws = Handler(config.server_address)
# setup has to be called before the connection is established
ws.setup({"subscribe" : Subscribe(), "sensor" : Sensor(),
while 1:
ws = Handler(config.server_address)
# setup has to be called before the connection is established
ws.setup({"subscribe" : Subscribe(), "sensor" : Sensor(),
"identify" : Identify(), "whoami" : WhoAmI(),
"stop_programs" : StopPrograms(), "shutdown" : Shutdown(),
"reboot" : Reboot(), "output" : Output()},
debug=False)
ws.connect()
try:
ws.connect()
break
except ConnectionRefusedError:
Logging.warning("Server not running... Retrying in 5s")
time.sleep(5)
ws.run_forever()
except KeyboardInterrupt:
ws.close()