fix: add graceful shutdown to CI deploy script

- scripts/ci_staging_deploy.sh: replace docker rm -f with docker stop + rm
  Worker: 300s, API: 30s, Web: 10s
- infra/docker/compose.yml: add stop_grace_period and stop_signal
  for api (30s) and worker (300s)
- infra/docker/entrypoint-worker.sh: add -W (warm shutdown) flag
  so Celery waits for current tasks before exiting on SIGTERM

Rollback function docker rm -f intentionally kept (speed priority)
This commit is contained in:
xiaoxia
2026-08-10 12:48:11 +08:00
committed by xiaoxia
parent c2a4bbc27a
commit 4cc2ee853d
3 changed files with 12 additions and 4 deletions
Regular → Executable
+4
View File
@@ -47,6 +47,8 @@ services:
container_name: xiaoxia-api-${ENV:-staging}
restart: unless-stopped
stop_grace_period: 30s
stop_signal: SIGTERM
# 环境变量文件(包含数据库密码等敏感信息)
env_file:
@@ -102,6 +104,8 @@ services:
container_name: xiaoxia-worker-${ENV:-staging}
restart: unless-stopped
stop_grace_period: 300s
stop_signal: SIGTERM
env_file:
- ../../.env
+2 -1
View File
@@ -10,4 +10,5 @@ exec celery \
-A worker_app.celery_app \
worker \
--loglevel=info \
"--concurrency=${CONCURRENCY}"
"--concurrency=${CONCURRENCY}" \
-W
+6 -3
View File
@@ -311,9 +311,12 @@ else
fi
echo "Stopping old containers..."
docker rm -f xiaoxia-api-staging 2>/dev/null || true
docker rm -f xiaoxia-worker-staging 2>/dev/null || true
docker rm -f xiaoxia-web-staging 2>/dev/null || true
# 优雅关闭:先 stop(发 SIGTERM,等待),再 rm
# Worker 需要更长时间(视频任务最长可能5分钟)
docker stop -t 300 xiaoxia-worker-staging 2>/dev/null || true
docker stop -t 30 xiaoxia-api-staging 2>/dev/null || true
docker stop -t 10 xiaoxia-web-staging 2>/dev/null || true
docker rm xiaoxia-worker-staging xiaoxia-api-staging xiaoxia-web-staging 2>/dev/null || true
LOG_OPTS="--log-driver json-file --log-opt max-size=50m --log-opt max-file=3"