fix: wait for services during deployment

This commit is contained in:
hectorzhao
2026-08-10 21:00:18 +08:00
parent 55aa054005
commit 0eb27e4ac0
4 changed files with 26 additions and 3 deletions
+16 -3
View File
@@ -89,9 +89,22 @@ systemctl restart cmpp-api
systemctl restart nginx
echo "[deploy] Health checks"
sleep 3
curl -fsS "http://127.0.0.1:${API_PORT:-3000}/api/health" >/dev/null
curl -fsS "http://127.0.0.1:8090/health" >/dev/null
wait_for_http() {
local name="$1"
local url="$2"
local attempt
# Nest初始化和活动通道恢复会随生产数据量波动;固定等待会把正常的慢启动误判为发布失败。
for attempt in $(seq 1 60); do
if curl -fsS "$url" >/dev/null 2>&1; then
return 0
fi
sleep 1
done
echo "$name did not become healthy within 60 seconds: $url" >&2
return 1
}
wait_for_http "API" "http://127.0.0.1:${API_PORT:-3000}/api/health"
wait_for_http "Gateway" "http://127.0.0.1:8090/health"
redis-cli -h "${REDIS_HOST:-127.0.0.1}" -p "${REDIS_PORT:-6379}" ping >/dev/null
pg_isready -d "${DATABASE_URL%%\?*}" >/dev/null