diff --git a/infra/docker/compose.yml b/infra/docker/compose.yml old mode 100644 new mode 100755 index b9e7178f5..5c7164c7e --- a/infra/docker/compose.yml +++ b/infra/docker/compose.yml @@ -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 diff --git a/infra/docker/entrypoint-worker.sh b/infra/docker/entrypoint-worker.sh old mode 100644 new mode 100755 index d03eb4bd1..9bbb6f898 --- a/infra/docker/entrypoint-worker.sh +++ b/infra/docker/entrypoint-worker.sh @@ -10,4 +10,5 @@ exec celery \ -A worker_app.celery_app \ worker \ --loglevel=info \ - "--concurrency=${CONCURRENCY}" + "--concurrency=${CONCURRENCY}" \ + -W diff --git a/scripts/ci_staging_deploy.sh b/scripts/ci_staging_deploy.sh index 71444545f..22a34a502 100755 --- a/scripts/ci_staging_deploy.sh +++ b/scripts/ci_staging_deploy.sh @@ -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"