- Import and call load_projects_cache() to populate cache before requests - Import and call generate_auth_token() to create one-time auth token - Import and call start_projects_watcher() for background cache refresh - Inject auth token into dashboard HTML via placeholder replacement - Add AMC_AUTH_TOKEN placeholder in index.html head
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import os
|
|
from http.server import ThreadingHTTPServer
|
|
|
|
from amc_server.context import DATA_DIR, PORT, generate_auth_token, start_projects_watcher
|
|
from amc_server.handler import AMCHandler
|
|
from amc_server.logging_utils import LOGGER, configure_logging, install_signal_handlers
|
|
from amc_server.mixins.spawn import load_projects_cache
|
|
|
|
|
|
def main():
|
|
configure_logging()
|
|
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
|
LOGGER.info("Starting AMC server")
|
|
|
|
# Initialize spawn feature
|
|
load_projects_cache()
|
|
generate_auth_token()
|
|
start_projects_watcher()
|
|
|
|
server = ThreadingHTTPServer(("127.0.0.1", PORT), AMCHandler)
|
|
install_signal_handlers(server)
|
|
LOGGER.info("AMC server listening on http://127.0.0.1:%s", PORT)
|
|
|
|
# Write PID file
|
|
pid_file = DATA_DIR / "server.pid"
|
|
pid_file.write_text(str(os.getpid()))
|
|
|
|
try:
|
|
server.serve_forever()
|
|
except KeyboardInterrupt:
|
|
LOGGER.info("AMC server interrupted; shutting down")
|
|
except Exception:
|
|
LOGGER.exception("AMC server crashed")
|
|
raise
|
|
finally:
|
|
pid_file.unlink(missing_ok=True)
|
|
server.server_close()
|
|
LOGGER.info("AMC server stopped")
|