""" Management script to let trusted users control OME. This should listen on localhost and have Caddy proxy with auth. """ from pathlib import Path import cherrypy from cherrypy.process.plugins import SignalHandler import admission import config import management import ovenapi import status import viewer cherrypy.config.update({ "server.socket_host": "127.0.0.1", "environment": "production", "tools.proxy.on": True, }) class Noop: pass def on_exit() -> None: config.save() cherrypy.engine.exit() if __name__ == "__main__": # Establish our config save-out signals signalhandler = SignalHandler(cherrypy.engine) signalhandler.handlers["SIGTERM"] = on_exit signalhandler.handlers["SIGHUP"] = on_exit signalhandler.handlers["SIGQUIT"] = on_exit signalhandler.handlers["SIGINT"] = on_exit signalhandler.subscribe() # Load config values config.load() # If we have API access, use it to pull our stream list into cache config.LAST_STREAM_LIST = ovenapi.get_api_handle( username=config.API_USER, password=config.API_PASS ).get_stream_list() runpath = Path(Path(__file__).parent.resolve(), "assets") cherrypy.tree.mount(admission.Admission(), "/admission") cherrypy.tree.mount(management.Management(), "/management") cherrypy.tree.mount(status.Status(), "/status") cherrypy.tree.mount(Noop(), "/assets", config={"/": {"tools.staticdir.on": True, "tools.staticdir.dir": runpath}}) cherrypy.tree.mount(viewer.Viewer(), "/") cherrypy.engine.start() cherrypy.engine.block()