#!/bin/bash # Start script for the FastAPI application # Exit on error set -e # Get the directory of this script DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # Set environment variables export PYTHONPATH="$DIR" export PYTHONUNBUFFERED=1 # Navigate to the application directory cd "$DIR" # Ensure log directory exists mkdir -p "$DIR/logs" # Detect Python path PYTHON_PATH=$(which python3 || which python) UVICORN_PATH=$(which uvicorn || echo "$DIR/venv/bin/uvicorn") echo "Starting application with Python at: $PYTHON_PATH" echo "Using uvicorn at: $UVICORN_PATH" echo "Working directory: $DIR" # Run database migrations if needed if [ -f "$DIR/alembic.ini" ]; then echo "Running database migrations..." "$PYTHON_PATH" -m alembic upgrade head || echo "Migration failed but continuing..." fi # Start the application with uvicorn using absolute paths echo "Starting application..." exec "$UVICORN_PATH" main:app --host 0.0.0.0 --port 8001 --workers 1 --no-access-log