This commit is contained in:
2025-06-15 19:49:54 +08:00
parent f62a34b49e
commit 8fa52bbd3a
2 changed files with 56 additions and 14 deletions

View File

@@ -1,13 +1,31 @@
#!/bin/sh
# 等待数据库就绪
echo "Waiting for database..."
sleep 5
# 执行数据库迁移
echo "Running database migrations..."
python manage.py migrate --noinput
# 收集静态文件
echo "Collecting static files..."
python manage.py collectstatic --noinput
# 计算worker数量 (CPU核心数 * 2 + 1)
WORKERS=$(python -c 'import multiprocessing; print(multiprocessing.cpu_count() * 2 + 1)')
# 启动 Gunicorn
echo "Starting Gunicorn with $WORKERS workers..."
exec gunicorn api.asgi:application \
--bind 0.0.0.0:8000 \
--worker-class uvicorn.workers.UvicornWorker \
--workers 4 \
--threads 2
--workers $WORKERS \
--threads 2 \
--timeout 120 \
--max-requests 1000 \
--max-requests-jitter 50 \
--keep-alive 5 \
--log-level error \
--capture-output \
--enable-stdio-inheritance