wrongmove/crawler/start.sh
2025-07-25 22:14:45 +00:00

49 lines
1.2 KiB
Bash
Executable file

#!/usr/bin/env bash
# This sript is used to start the backend services and configure them according to what's available in the system
set -eux
ENV_MODE=${ENV:-"dev"} # Defaults to "dev" if ENV_MODE is unset
echo "Checking connection to redis is successful..."
python celery_app.py
case "$ENV_MODE" in
dev)
echo "🛠️ Running in DEVELOPMENT mode"
set +e
pkill -f celery
pkill watchmedo
set -e
watchmedo auto-restart --directory=./ --pattern='*.py' --recursive -- celery -A celery_app worker & # DEV to autoreload on changes
CELERY_PID=$!
;;
prod)
echo "🚀 Running in PRODUCTION mode"
alembic upgrade head
celery -A celery_app worker --beat &
CELERY_PID=$!
;;
*)
echo "❌ Unknown ENV_MODE: $ENV_MODE. Defaulting to DEV."
exit 1
;;
esac
cleanup() {
echo "Stopping background process (PID: $CELERY_PID)..."
kill "$CELERY_PID" 2>/dev/null # Graceful shutdown (SIGTERM)
wait "$CELERY_PID" 2>/dev/null # Wait for process to exit
}
trap cleanup EXIT SIGINT SIGTERM
# celery -A celery_app worker -D # PROD
uvicorn api.app:app --host 0.0.0.0 --port 5001 --reload --reload-exclude "data" --log-level debug
# UVICORN_PID=$!
# wait for
# less /etc/passwd > /dev/null