modified: README.md modified: compose.yml modified: configuration.py new file: haproxy.cfg new file: init-patroni-users.sql renamed: entrypoint.sh -> netbox-entrypoint.sh renamed: Containerfile -> netbox.Containerfile modified: nginx.conf new file: patroni-entrypoint.sh new file: patroni.Containerfile new file: patroni.yml
84 lines
2.4 KiB
Bash
84 lines
2.4 KiB
Bash
#!/usr/bin/env bash
|
||
# ============================================================
|
||
# /netbox-entrypoint.sh – NetBox container entrypoint
|
||
# ============================================================
|
||
set -euo pipefail
|
||
|
||
NETBOX_ROOT=/opt/netbox/netbox
|
||
MANAGE="${NETBOX_ROOT}/manage.py"
|
||
|
||
#RETRIES=10
|
||
wait_for_db() {
|
||
#until python "${MANAGE}" migrate --check &>/dev/null; do
|
||
until python "${MANAGE}" check --database default &>/dev/null; do
|
||
echo "[entrypoint] Waiting for database …"
|
||
# if (( RETRIES == 0 )); then
|
||
# echo "[entrypoint] Database did not become ready."
|
||
# exit 1
|
||
# fi
|
||
# ((RETRIES--))
|
||
sleep 2
|
||
done
|
||
echo "[entrypoint] Database is ready."
|
||
}
|
||
|
||
run_migrations() {
|
||
echo "[entrypoint] Applying database migrations …"
|
||
python "${MANAGE}" migrate --no-input
|
||
}
|
||
|
||
run_collectstatic() {
|
||
echo "[entrypoint] Collecting static files …"
|
||
python "${MANAGE}" collectstatic --no-input --clear
|
||
}
|
||
|
||
case "${1:-gunicorn}" in
|
||
gunicorn)
|
||
wait_for_db
|
||
run_migrations
|
||
run_collectstatic
|
||
echo "[entrypoint] Starting Gunicorn …"
|
||
cd $NETBOX_ROOT
|
||
exec gunicorn \
|
||
--bind "${GUNICORN_BIND:-localhost:8080}" \
|
||
--workers "${GUNICORN_WORKERS:-4}" \
|
||
--worker-class "${GUNICORN_WORKER_CLASS:-gthread}" \
|
||
--threads "${GUNICORN_THREADS:-3}" \
|
||
--timeout "${GUNICORN_TIMEOUT:-120}" \
|
||
--max-requests "${GUNICORN_MAX_REQUESTS:-5000}" \
|
||
--max-requests-jitter "${GUNICORN_MAX_REQUESTS_JITTER:-500}" \
|
||
--log-level "${GUNICORN_LOG_LEVEL:-info}" \
|
||
--access-logfile - \
|
||
--error-logfile - \
|
||
netbox.wsgi
|
||
;;
|
||
|
||
worker)
|
||
wait_for_db
|
||
echo "[entrypoint] Starting RQ worker …"
|
||
exec python "${MANAGE}" rqworker \
|
||
high default low
|
||
;;
|
||
|
||
dns-transfer-endpoint)
|
||
wait_for_db
|
||
echo "[entrypoint] Starting DNS Transfer Endpoint …"
|
||
exec python "${MANAGE}" dns-transfer-endpoint --address ::1
|
||
;;
|
||
|
||
housekeeping)
|
||
wait_for_db
|
||
echo "[entrypoint] Running housekeeping …"
|
||
exec python "${MANAGE}" housekeeping
|
||
;;
|
||
|
||
shell)
|
||
exec python "${MANAGE}" shell
|
||
;;
|
||
|
||
*)
|
||
# Pass-through for arbitrary commands (e.g. manage.py subcommands)
|
||
exec python "${MANAGE}" "$@"
|
||
;;
|
||
esac
|