openwebrx-clone/owrx/__main__.py

83 lines
2.5 KiB
Python
Raw Normal View History

2019-12-08 16:15:48 +00:00
from http.server import HTTPServer
from owrx.http import RequestHandler
from owrx.config import Config, CoreConfig
2019-12-08 16:15:48 +00:00
from owrx.feature import FeatureDetector
from owrx.sdr import SdrService
2019-12-08 16:15:48 +00:00
from socketserver import ThreadingMixIn
from owrx.service import Services
from owrx.websocket import WebSocketConnection
from owrx.reporting import ReportingEngine
2020-03-15 22:34:44 +00:00
from owrx.version import openwebrx_version
from owrx.audio import DecoderQueue
2021-01-22 16:33:53 +00:00
import signal
import logging
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
logger = logging.getLogger(__name__)
2019-12-08 16:15:48 +00:00
class ThreadedHttpServer(ThreadingMixIn, HTTPServer):
pass
2021-01-22 16:33:53 +00:00
class SignalException(Exception):
pass
def handleSignal(sig, frame):
raise SignalException("Received Signal {sig}".format(sig=sig))
2019-12-08 16:15:48 +00:00
def main():
print(
"""
OpenWebRX - Open Source SDR Web App for Everyone! | for license see LICENSE file in the package
_________________________________________________________________________________________________
Author contact info: Jakob Ketterl, DD5JFK <dd5jfk@darc.de>
2020-03-15 22:39:38 +00:00
Documentation: https://github.com/jketterl/openwebrx/wiki
Support and info: https://groups.io/g/openwebrx
2019-12-08 16:15:48 +00:00
"""
)
2020-03-15 22:34:44 +00:00
logger.info("OpenWebRX version {0} starting up...".format(openwebrx_version))
2021-01-22 16:33:53 +00:00
for sig in [signal.SIGINT, signal.SIGTERM]:
signal.signal(sig, handleSignal)
pm = Config.get()
2019-12-08 16:15:48 +00:00
configErrors = Config.validateConfig()
if configErrors:
2021-01-20 16:01:46 +00:00
logger.error("your configuration contains errors. please address the following errors:")
for e in configErrors:
logger.error(e)
return
2019-12-08 16:15:48 +00:00
featureDetector = FeatureDetector()
if not featureDetector.is_available("core"):
logger.error(
2019-12-08 16:15:48 +00:00
"you are missing required dependencies to run openwebrx. "
2020-08-26 18:07:58 +00:00
"please check that the following core requirements are installed and up to date:"
2019-12-08 16:15:48 +00:00
)
logger.error(", ".join(featureDetector.get_requirements("core")))
2019-12-08 16:15:48 +00:00
return
# Get error messages about unknown / unavailable features as soon as possible
# start up "always-on" sources right away
SdrService.getSources()
2019-12-08 16:15:48 +00:00
Services.start()
try:
server = ThreadedHttpServer(("0.0.0.0", CoreConfig().get_web_port()), RequestHandler)
2019-12-08 16:15:48 +00:00
server.serve_forever()
2021-01-22 16:33:53 +00:00
except SignalException:
2019-12-08 16:15:48 +00:00
WebSocketConnection.closeAll()
Services.stop()
2021-01-14 21:55:35 +00:00
ReportingEngine.stopAll()
DecoderQueue.stopAll()