wrongmove/crawler/start.sh

55 lines
1.5 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
case "$ENV_MODE" in
dev)
echo "🛠️ Running in DEVELOPMENT mode"
set +e
pkill -f celery
pkill watchmedo
set -e
if ! netstat -tlnp |grep 6379; then
echo "Did not find a running redis on 6379. Starting a new instance..."
docker run -d --rm --name redis-server -p 6379:6379 redis:latest
fi
echo "Checking connection to redis is successful..."
python celery_app.py
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"
echo "Checking connection to redis is successful..."
python celery_app.py
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 --log-level debug
# UVICORN_PID=$!
# wait for
# less /etc/passwd > /dev/null