kumistatus/server.py

29 lines
1.1 KiB
Python
Raw Normal View History

2016-07-16 17:50:17 +00:00
#!/usr/bin/env python3
2016-07-18 15:39:55 +00:00
import setuptools, servertools, socketserver, syslog, threading
2016-07-16 17:50:17 +00:00
if __name__ == "__main__":
socketserver.TCPServer.allow_reuse_address = True
2016-07-20 17:30:51 +00:00
bind = setuptools.getSetting("Server", "bind") or "0.0.0.0"
port = int(setuptools.getSetting("Server", "port")) or 5747
2016-07-16 17:50:17 +00:00
try:
2016-07-20 17:30:51 +00:00
server = servertools.TCPServer((bind, port), servertools.TCPHandler)
2016-07-16 17:50:17 +00:00
except:
2016-07-20 17:30:51 +00:00
servertools.logger("Unable to bind on %s:%i. Make sure the port is not in use or use a different port." % (bind, port))
servertools.shutdown(status=1)
2016-07-20 17:30:51 +00:00
servertools.logger("Kumi Status server running on %s:%i." % (bind, port))
2016-07-16 17:50:17 +00:00
try:
thread = threading.Thread(target=server.serve_forever(), daemon=True)
except KeyboardInterrupt:
servertools.logger("Caught KeyboardInterrupt. Shutting down.")
servertools.shutdown()
2016-07-16 17:50:17 +00:00
except EOFError:
servertools.logger("Caught EOF. Shutting down.")
servertools.shutdown()
2016-07-16 17:50:17 +00:00
except BaseException as e:
servertools.logger(str(e), syslog.LOG_CRIT)
servertools.logger("Caught some bad exception. Trying to reload...", syslog.LOG_CRIT)
servertools.shutdown(reboot=True, status=2)
2016-07-16 17:50:17 +00:00