"""
Bootstrap of last resort for ``worker_manager.py``.

Lifecycle management itself belongs to ``worker_manager.py`` — a small
long-lived supervisor that watches ``worker.py`` every 30 seconds and restarts
it on crash. Since ``wsgi.py`` also calls ``worker_manager.ensure_running()``
on every web-process start (see that module's docstring), this script is no
longer the primary way the manager gets started — it is the fallback for when
NOTHING has imported wsgi.py in a while (the Passenger app itself was reaped,
recycled without a fresh import, etc). There is no systemd on shared hosting,
so cron is the only scheduler that reliably survives all of that, which is why
it stays as the outermost safety net.

Because two different call sites (wsgi.py and this script) both end up
calling the very same idempotent ``ensure_running()``, it is a genuine no-op
whichever one gets there first — no duplicate managers, regardless of how
often either one fires.

    */10 * * * * /home/USER/virtualenv/APP/3.12/bin/python \
                 /home/USER/APP_ROOT/cron_keepalive.py >> \
                 /home/USER/APP_ROOT/logs/cron.log 2>&1
"""

import os
import sys

PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
if PROJECT_DIR not in sys.path:
    sys.path.insert(0, PROJECT_DIR)


def main():
    import worker_manager

    worker_manager.ensure_running()


if __name__ == "__main__":
    main()
