fix(boot): bound post-start health poll so a slow API cannot kill PM2 (BIT-32855) (#296)
This commit was merged in pull request #296.
This commit is contained in:
commit
88e74d34ba
1 file changed
+10
-3
+10
-3
@@ -12,7 +12,14 @@ unset PORT DEPLOY_WEBHOOK_SECRET DEPLOY_SERVICE DEPLOY_SCRIPT DEPLOY_LOG
|
||||
REPO_DIR="${DEPLOY_REPO_DIR:-/srv/photoreport}"
|
||||
API_PORT="${API_PORT:-3000}"
|
||||
SITE_PORT="${SITE_PORT:-3100}"
|
||||
HEALTH_TRIES="${BOOT_HEALTH_TRIES:-90}"
|
||||
# Bound the post-start health poll by wall-clock, not by a try count. A count of 90 (sleep 2 +
|
||||
# max-time 3) could run ~450s and exceed photoreport-boot.service's TimeoutStartSec, at which
|
||||
# point systemd kills the whole cgroup — including the PM2 daemon this script just launched —
|
||||
# and leaves the port closed with no self-heal (BIT-32855: pr-site turned a transient pr-api
|
||||
# reboot into a persistent 502 this way). PM2 (autorestart) and the next-env watchdog handle
|
||||
# real recovery; this poll only confirms the boot, so a 150s budget fits under both the
|
||||
# deployed 300s and the repo's 420s TimeoutStartSec with margin for the pm2_start retry path.
|
||||
HEALTH_BUDGET_SEC="${BOOT_HEALTH_BUDGET_SEC:-150}"
|
||||
|
||||
log() { printf '[%s] boot %s: %s\n' "$(date -u +%FT%TZ)" "$SERVICE" "$*"; }
|
||||
|
||||
@@ -31,8 +38,8 @@ cd "$REPO_DIR"
|
||||
SHA="$(git rev-parse HEAD)"
|
||||
|
||||
wait_for() {
|
||||
local url="$1" i
|
||||
for ((i = 1; i <= HEALTH_TRIES; i++)); do
|
||||
local url="$1" start=$SECONDS
|
||||
while (( SECONDS - start < HEALTH_BUDGET_SEC )); do
|
||||
curl -fsS --max-time 3 -o /dev/null "$url" 2>/dev/null && return 0
|
||||
sleep 2
|
||||
done
|
||||
|
||||
Reference in new issue
Block a user