2021-04-26 22:53:45 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
# the linter will complain about this, but the logging must be configured before importing all the other modules
|
|
|
|
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
|
|
|
from http.server import HTTPServer
|
|
|
|
from owrx.http import RequestHandler
|
2021-02-11 18:31:44 +00:00
|
|
|
from owrx.config.core import CoreConfig
|
|
|
|
from owrx.config import Config
|
2021-04-26 17:27:12 +00:00
|
|
|
from owrx.config.commands import MigrateCommand
|
2019-12-08 16:15:48 +00:00
|
|
|
from owrx.feature import FeatureDetector
|
2019-12-21 19:58:28 +00:00
|
|
|
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
|
2021-01-14 19:52:56 +00:00
|
|
|
from owrx.reporting import ReportingEngine
|
2020-03-15 22:34:44 +00:00
|
|
|
from owrx.version import openwebrx_version
|
2021-04-11 12:40:28 +00:00
|
|
|
from owrx.audio.queue import DecoderQueue
|
2021-04-24 17:39:48 +00:00
|
|
|
from owrx.admin import add_admin_parser, run_admin_action
|
2021-01-22 16:33:53 +00:00
|
|
|
import signal
|
2021-04-24 17:39:48 +00:00
|
|
|
import argparse
|
2021-01-22 16:33:53 +00:00
|
|
|
|
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():
|
2021-04-24 17:39:48 +00:00
|
|
|
parser = argparse.ArgumentParser(description="OpenWebRX - Open Source SDR Web App for Everyone!")
|
|
|
|
parser.add_argument("-v", "--version", action="store_true", help="Show the software version")
|
2021-04-26 22:33:52 +00:00
|
|
|
parser.add_argument("--debug", action="store_true", help="Set loglevel to DEBUG")
|
2021-04-24 17:39:48 +00:00
|
|
|
|
|
|
|
moduleparser = parser.add_subparsers(title="Modules", dest="module")
|
2021-04-26 17:27:12 +00:00
|
|
|
adminparser = moduleparser.add_parser("admin", help="Administration actions")
|
2021-04-24 17:39:48 +00:00
|
|
|
add_admin_parser(adminparser)
|
|
|
|
|
2021-04-26 17:27:12 +00:00
|
|
|
configparser = moduleparser.add_parser("config", help="Configuration actions")
|
|
|
|
configcommandparser = configparser.add_subparsers(title="Commands", dest="command")
|
|
|
|
|
2021-04-26 17:34:50 +00:00
|
|
|
migrateparser = configcommandparser.add_parser("migrate", help="Migrate configuration files")
|
2021-04-26 17:27:12 +00:00
|
|
|
migrateparser.set_defaults(cls=MigrateCommand)
|
|
|
|
|
2021-04-24 17:39:48 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2021-04-26 22:45:14 +00:00
|
|
|
# set loglevel to info for CLI commands
|
|
|
|
if args.module is not None and not args.debug:
|
|
|
|
logging.getLogger().setLevel(logging.INFO)
|
2021-04-26 22:33:52 +00:00
|
|
|
|
2021-04-24 17:39:48 +00:00
|
|
|
if args.version:
|
|
|
|
print("OpenWebRX version {version}".format(version=openwebrx_version))
|
2021-04-26 17:34:50 +00:00
|
|
|
elif args.module == "admin":
|
2021-04-24 17:39:48 +00:00
|
|
|
run_admin_action(adminparser, args)
|
2021-04-26 17:34:50 +00:00
|
|
|
elif args.module == "config":
|
|
|
|
run_admin_action(configparser, args)
|
2021-04-24 17:39:48 +00:00
|
|
|
else:
|
|
|
|
start_receiver()
|
|
|
|
|
|
|
|
|
|
|
|
def start_receiver():
|
2019-12-08 16:15:48 +00:00
|
|
|
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)
|
|
|
|
|
2021-02-06 21:08:27 +00:00
|
|
|
# config warmup
|
|
|
|
Config.validateConfig()
|
|
|
|
coreConfig = CoreConfig()
|
2020-03-15 22:32:19 +00:00
|
|
|
|
2019-12-08 16:15:48 +00:00
|
|
|
featureDetector = FeatureDetector()
|
2022-06-01 15:11:45 +00:00
|
|
|
failed = featureDetector.get_failed_requirements("core")
|
|
|
|
if failed:
|
2020-03-15 22:32:19 +00:00
|
|
|
logger.error(
|
2019-12-08 16:15:48 +00:00
|
|
|
"you are missing required dependencies to run openwebrx. "
|
2022-06-01 15:11:45 +00:00
|
|
|
"please check that the following core requirements are installed and up to date: %s",
|
|
|
|
", ".join(failed)
|
2019-12-08 16:15:48 +00:00
|
|
|
)
|
2022-06-01 15:11:45 +00:00
|
|
|
for f in failed:
|
|
|
|
description = featureDetector.get_requirement_description(f)
|
|
|
|
if description:
|
|
|
|
logger.error("description for %s:\n%s", f, description)
|
2019-12-08 16:15:48 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
# Get error messages about unknown / unavailable features as soon as possible
|
2020-12-10 17:28:10 +00:00
|
|
|
# start up "always-on" sources right away
|
2021-03-18 20:53:59 +00:00
|
|
|
SdrService.getAllSources()
|
2019-12-08 16:15:48 +00:00
|
|
|
|
|
|
|
Services.start()
|
|
|
|
|
|
|
|
try:
|
2021-02-06 21:08:27 +00:00
|
|
|
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:
|
2021-04-11 16:42:35 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
WebSocketConnection.closeAll()
|
|
|
|
Services.stop()
|
2021-09-15 13:03:11 +00:00
|
|
|
SdrService.stopAllSources()
|
2021-04-11 16:42:35 +00:00
|
|
|
ReportingEngine.stopAll()
|
|
|
|
DecoderQueue.stopAll()
|