#!/usr/bin/python3
"""autodistd entry point.

Installed as /usr/bin/autodistd by the autodist package's Makefile.
Normally kept resident by the plain autodistd.service systemd unit,
installed alongside it (see systemd/autodistd.service in this directory).

On the buildvm-* Docker images, autodistd is started (and, if it exits for
any reason, restarted) by a small supervisor script that is itself the
container's CMD -- see rootfiles/usr/local/bin/buildvm-init in the
openmamba-docker-buildvm repository. That script is also what starts
Apache there. Nothing here needs to know it's running under Docker: no
flags, no signal-triggered self-reexec -- picking up a code change (e.g.
after `dnf update autodist`) is just `pkill -f /usr/bin/autodistd` either
way, and whatever is supervising this process (systemd, or that script)
brings a fresh one back up on its own.
"""
import os
import sys

_HERE = os.path.dirname(os.path.abspath(__file__))
for _candidate in ("/usr/share/autodist", _HERE):
    if _candidate not in sys.path:
        sys.path.insert(0, _candidate)

import uvicorn  # noqa: E402

from autodistd_app.config import load_autodistd_conf  # noqa: E402

if __name__ == "__main__":
    port = int(load_autodistd_conf().get("AUTODISTD_PORT") or "8021")
    uvicorn.run("autodistd_app.api:app", host="0.0.0.0", port=port, log_level="info")
