From a4e480e108717d76deeae3823bf7e2e9eac8065d Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Wed, 3 Jun 2026 23:51:59 +0000 Subject: [PATCH] Upload prestart.sh --- prestart.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 prestart.sh diff --git a/prestart.sh b/prestart.sh new file mode 100644 index 0000000..117f446 --- /dev/null +++ b/prestart.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# ============================================================================= +# prestart.sh — Container entrypoint for CRM System +# +# Responsibilities: +# 1. Run Alembic DB migrations (alembic upgrade head). +# 2. Start uvicorn as PID 1 (so signals like SIGTERM are forwarded correctly). +# +# Notes: +# - `set -e` ensures the container crashes loudly if migrations fail, +# rather than starting a broken app on an inconsistent schema. +# - `exec uvicorn ...` replaces the shell process with uvicorn, so uvicorn +# becomes PID 1 and receives Docker's SIGTERM directly for graceful shutdown. +# - `--workers 1` is intentional for v1: SQLite (dev) is single-threaded, +# and asyncpg (prod) scales fine with one worker + an async connection pool. +# ============================================================================= + +set -e + +echo "[prestart] $(date -u +%Y-%m-%dT%H:%M:%SZ) - Running alembic upgrade head..." +alembic upgrade head +echo "[prestart] DB migrations completed successfully." + +echo "[prestart] Starting uvicorn on 0.0.0.0:8000 (workers=1)..." +exec uvicorn app.main:app \ + --host 0.0.0.0 \ + --port 8000 \ + --workers 1