#!/bin/bash set -e echo "Starting STUPA PDF API Backend..." # Wait for database to be ready echo "Waiting for database..." while ! nc -z ${MYSQL_HOST:-db} ${MYSQL_PORT:-3306}; do sleep 1 done echo "Database is ready!" # Run database initialization echo "Initializing database..." python -m src.startup || { echo "Warning: Database initialization failed or already initialized" } # Run migrations if alembic is available if [ -f "alembic.ini" ]; then echo "Running database migrations..." alembic upgrade head || { echo "Warning: Migrations failed or not configured" } fi # Start the application echo "Starting application server..." exec uvicorn src.main:app \ --host 0.0.0.0 \ --port ${PORT:-8000} \ --workers ${WORKERS:-1} \ --reload-dir /app/src \ ${UVICORN_ARGS}