diff --git a/owrx/__main__.py b/owrx/__main__.py index 1903d8b..1a39cb1 100644 --- a/owrx/__main__.py +++ b/owrx/__main__.py @@ -1,8 +1,3 @@ -import logging - -logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s") -logger = logging.getLogger(__name__) - from http.server import HTTPServer from owrx.http import RequestHandler from owrx.config import Config @@ -14,12 +9,26 @@ from owrx.websocket import WebSocketConnection from owrx.reporting import ReportingEngine from owrx.version import openwebrx_version from owrx.audio import DecoderQueue +import signal + +import logging + +logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s") +logger = logging.getLogger(__name__) class ThreadedHttpServer(ThreadingMixIn, HTTPServer): pass +class SignalException(Exception): + pass + + +def handleSignal(sig, frame): + raise SignalException("Received Signal {sig}".format(sig=sig)) + + def main(): print( """ @@ -36,6 +45,9 @@ Support and info: https://groups.io/g/openwebrx logger.info("OpenWebRX version {0} starting up...".format(openwebrx_version)) + for sig in [signal.SIGINT, signal.SIGTERM]: + signal.signal(sig, handleSignal) + pm = Config.get() configErrors = Config.validateConfig() @@ -63,7 +75,7 @@ Support and info: https://groups.io/g/openwebrx try: server = ThreadedHttpServer(("0.0.0.0", pm["web_port"]), RequestHandler) server.serve_forever() - except KeyboardInterrupt: + except SignalException: WebSocketConnection.closeAll() Services.stop() ReportingEngine.stopAll()