36 lines
1.2 KiB
Bash
36 lines
1.2 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
# ฟังก์ชันสำหรับเตรียมระบบ Backend
|
|
prepare_backend() {
|
|
echo "--- Collecting static files ---"
|
|
python manage.py collectstatic --noinput
|
|
|
|
echo "--- Applying database migrations ---"
|
|
python manage.py migrate --noinput
|
|
}
|
|
|
|
# ตรวจสอบพารามิเตอร์ที่ส่งมาจาก Kubernetes Deployment (command/args)
|
|
if [ "$1" = "gunicorn" ]; then
|
|
prepare_backend
|
|
|
|
# ดึงค่า PORT และ WORKERS จาก Env (ถ้ามี) หรือใช้ค่า Default
|
|
APP_PORT=${PORT:-8000}
|
|
WORKERS=${GUNICORN_WORKERS:-3}
|
|
|
|
echo "Starting Gunicorn on port $APP_PORT with $WORKERS workers..."
|
|
exec gunicorn --bind 0.0.0.0:$APP_PORT \
|
|
--workers $WORKERS \
|
|
--access-logfile - \
|
|
--error-logfile - \
|
|
core.wsgi:application
|
|
|
|
elif [ "$1" = "celery" ]; then
|
|
echo "Starting Celery Worker..."
|
|
exec celery -A core worker -l info
|
|
|
|
else
|
|
# สำหรับคำสั่งอื่นๆ เช่น python manage.py createsuperuser
|
|
echo "Executing custom command: $@"
|
|
exec "$@"
|
|
fi |