2024-05-10 23:15:29 +08:00
|
|
|
#!/bin/bash
|
2024-08-30 19:28:24 +08:00
|
|
|
# read .env values
|
|
|
|
awk -F= '$1 == "BACKEND_DEBUG" {print $2}' .env
|
|
|
|
awk -F= '$1 == "BACKEND_PORT" {print $2}' .env
|
|
|
|
awk -F= '$1 == "CELERY_FLOWER_PORT" {print $2}' .env
|
2024-05-10 23:15:29 +08:00
|
|
|
|
|
|
|
echo "Running as: $RUN_TYPE"
|
2024-08-30 19:28:24 +08:00
|
|
|
cd backend/
|
2024-05-10 23:15:29 +08:00
|
|
|
if [ "$RUN_TYPE" = "web" ]; then
|
2024-08-30 19:28:24 +08:00
|
|
|
python manage.py graph_models -o ../documentation/erd/app_models.png
|
|
|
|
python manage.py spectacular --color --file schema.yml
|
|
|
|
python manage.py migrate
|
|
|
|
if [ ! -d "static" ]; then
|
2024-05-10 23:15:29 +08:00
|
|
|
echo "Generating static files"
|
2024-08-30 19:28:24 +08:00
|
|
|
python manage.py collectstatic --noinput
|
|
|
|
fi
|
|
|
|
if [ "$BACKEND_DEBUG" = 'True' ]; then
|
|
|
|
python manage.py runserver "0.0.0.0:${BACKEND_PORT:-8000}"
|
|
|
|
else
|
|
|
|
python -m granian --host 0.0.0.0 --port "${BACKEND_PORT:-8000}" --workers 8 --interface wsgi config.wsgi:application
|
2024-05-10 23:15:29 +08:00
|
|
|
fi
|
|
|
|
elif [ "$RUN_TYPE" = "worker" ]; then
|
2024-08-30 19:28:24 +08:00
|
|
|
celery -A config worker -l INFO -E --concurrency 1
|
2024-05-10 23:15:29 +08:00
|
|
|
elif [ "$RUN_TYPE" = "beat" ]; then
|
|
|
|
sleep 15
|
2024-08-30 19:28:24 +08:00
|
|
|
celery -A config beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler
|
2024-05-10 23:15:29 +08:00
|
|
|
elif [ "$RUN_TYPE" = "monitor" ]; then
|
2024-08-30 19:28:24 +08:00
|
|
|
celery -A config flower --port="${CELERY_FLOWER_PORT:-5555}"
|
2024-05-10 23:15:29 +08:00
|
|
|
else
|
2024-08-30 19:28:24 +08:00
|
|
|
echo "No RUN_TYPE value set. Exiting"
|
|
|
|
exit 1
|
2024-05-10 23:15:29 +08:00
|
|
|
fi
|