From 54defa4429d84bb51ceb0c20809fb0ca09bcf104 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Wed, 9 Sep 2026 18:42:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Worker=20health=20check=20=E6=89=AB?= =?UTF-8?q?=E6=8F=8F=E5=85=A8=E9=83=A8=20/proc=20=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20unhealthy=20=E8=AF=AF=E5=88=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:Worker 容器内无 pgrep/ps 工具,旧 health check 使用 'grep -q celery /proc/1/cmdline' 检查 PID 1 的 cmdline, 但 PID 1 是 entrypoint-worker.sh(bash 脚本),不含 celery 关键字, 导致 health check 永远返回 unhealthy。 同时部署脚本中 sh -c 嵌套引号导致 $pid 变量被外层 shell 提前展开为空。 修复:改用 grep -lq celery /proc/[0-9]*/cmdline 扫描所有进程 cmdline, 找到任意 celery 进程即判定 healthy。无需变量、无嵌套 shell、无 pgrep 依赖。 影响文件: - infra/docker/compose.yml - infra/docker/deploy-staging-registry.sh - infra/docker/deploy-production-registry.sh --- infra/docker/compose.yml | 4 ++-- infra/docker/deploy-production-registry.sh | 2 +- infra/docker/deploy-staging-registry.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/infra/docker/compose.yml b/infra/docker/compose.yml index b0ce86443..46bfc0e74 100755 --- a/infra/docker/compose.yml +++ b/infra/docker/compose.yml @@ -128,9 +128,9 @@ services: - xiaoxia-net # 健康检查配置 - # 注:celery inspect ping 依赖 broker 连接,在容器内不可靠,改用进程检查 + # 注:容器内无 pgrep/ps,扫描 /proc 所有进程的 cmdline 查找 celery 进程 healthcheck: - test: ["CMD-SHELL", "for pid in /proc/[0-9]*/cmdline; do if grep -ql celery \"$pid\" 2>/dev/null; then exit 0; fi; done; exit 1"] + test: ["CMD-SHELL", "grep -lq celery /proc/[0-9]*/cmdline 2>/dev/null || exit 1"] interval: 30s timeout: 10s retries: 3 diff --git a/infra/docker/deploy-production-registry.sh b/infra/docker/deploy-production-registry.sh index e9a4a6a27..c0a78f05f 100755 --- a/infra/docker/deploy-production-registry.sh +++ b/infra/docker/deploy-production-registry.sh @@ -155,7 +155,7 @@ docker run -d \ --restart unless-stopped \ --cpus 2 \ --memory 2g \ - --health-cmd "sh -c \"for pid in /proc/[0-9]*/cmdline; do if grep -ql celery \"$pid\" 2>/dev/null; then exit 0; fi; done; exit 1\"" \ + --health-cmd "sh -c \"grep -lq celery /proc/[0-9]*/cmdline 2>/dev/null || exit 1\"" \ --health-interval 30s \ --health-timeout 10s \ --health-retries 3 \ diff --git a/infra/docker/deploy-staging-registry.sh b/infra/docker/deploy-staging-registry.sh index e7494c9b3..c5441d9f9 100755 --- a/infra/docker/deploy-staging-registry.sh +++ b/infra/docker/deploy-staging-registry.sh @@ -116,7 +116,7 @@ docker run -d \ -v "$GENERATED_DIR:/app/generated" \ --restart unless-stopped \ --label com.centurylinklabs.watchtower.enable=true \ - --health-cmd "sh -c \"for pid in /proc/[0-9]*/cmdline; do if grep -ql celery \"$pid\" 2>/dev/null; then exit 0; fi; done; exit 1\"" \ + --health-cmd "sh -c \"grep -lq celery /proc/[0-9]*/cmdline 2>/dev/null || exit 1\"" \ --health-interval 30s \ --health-timeout 10s \ --health-retries 3 \ -- 2.54.0