28 lines
1.1 KiB
Python
Executable file
28 lines
1.1 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import setuptools, servertools, socketserver, syslog, threading
|
|
|
|
if __name__ == "__main__":
|
|
socketserver.TCPServer.allow_reuse_address = True
|
|
bind = setuptools.getSetting("Server", "bind") or "0.0.0.0"
|
|
port = int(setuptools.getSetting("Server", "port")) or 5747
|
|
try:
|
|
server = servertools.TCPServer((bind, port), servertools.TCPHandler)
|
|
except:
|
|
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)
|
|
servertools.logger("Kumi Status server running on %s:%i." % (bind, port))
|
|
|
|
try:
|
|
thread = threading.Thread(target=server.serve_forever(), daemon=True)
|
|
except KeyboardInterrupt:
|
|
servertools.logger("Caught KeyboardInterrupt. Shutting down.")
|
|
servertools.shutdown()
|
|
except EOFError:
|
|
servertools.logger("Caught EOF. Shutting down.")
|
|
servertools.shutdown()
|
|
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)
|
|
|