T0.1: Separate redis-auth service (64mb, noeviction) for auth state
T0.2: Bump data Redis from 256mb to 1gb
T0.3: Per-app DATABASE_URL via PgBouncer to per-domain databases
T0.4: PgBouncer service (transaction mode, pool=20, max_conn=300);
session.py pools reduced to 3+5 with timeout and recycle
T0.5: Hypercorn --workers 2 --keep-alive 75 on all 6 entrypoints
Deploy requires running split-databases.sh first to create per-domain
databases from the existing appdb.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
33 lines
1.0 KiB
Bash
33 lines
1.0 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# Optional: wait for Postgres to be reachable
|
|
if [[ -n "${DATABASE_HOST:-}" && -n "${DATABASE_PORT:-}" ]]; then
|
|
echo "Waiting for Postgres at ${DATABASE_HOST}:${DATABASE_PORT}..."
|
|
for i in {1..60}; do
|
|
(echo > /dev/tcp/${DATABASE_HOST}/${DATABASE_PORT}) >/dev/null 2>&1 && break || true
|
|
sleep 1
|
|
done
|
|
fi
|
|
|
|
# Run DB migrations only if RUN_MIGRATIONS=true (blog service only)
|
|
if [[ "${RUN_MIGRATIONS:-}" == "true" ]]; then
|
|
echo "Running Alembic migrations..."
|
|
(cd shared && alembic upgrade head)
|
|
fi
|
|
|
|
# Clear Redis page cache on deploy
|
|
if [[ -n "${REDIS_URL:-}" && "${REDIS_URL}" != "no" ]]; then
|
|
echo "Flushing Redis cache..."
|
|
python3 -c "
|
|
import redis, os
|
|
r = redis.from_url(os.environ['REDIS_URL'])
|
|
r.flushdb()
|
|
print('Redis cache cleared.')
|
|
" || echo "Redis flush failed (non-fatal), continuing..."
|
|
fi
|
|
|
|
# Start the app
|
|
echo "Starting Hypercorn (${APP_MODULE:-app:app})..."
|
|
PYTHONUNBUFFERED=1 exec hypercorn "${APP_MODULE:-app:app}" --bind 0.0.0.0:${PORT:-8000} --workers ${WORKERS:-2} --keep-alive 75
|