diff --git a/infra/staging/deploy_staging.sh b/infra/staging/deploy_staging.sh index daca091..5bbe01a 100755 --- a/infra/staging/deploy_staging.sh +++ b/infra/staging/deploy_staging.sh @@ -66,7 +66,31 @@ chown -R wpp:wpp "${APP_DIR}" runuser -u wpp -- test -w "${APP_DIR}" systemctl restart wpp-staging.service -curl -fsS http://127.0.0.1:8000/healthz + +HEALTH_URL="http://127.0.0.1:8000/healthz" +MAX_ATTEMPTS=7 +SLEEP_SECONDS=1 +ATTEMPT=1 + +until curl -fsS "${HEALTH_URL}" >/dev/null; do + if [ "${ATTEMPT}" -ge "${MAX_ATTEMPTS}" ]; then + echo "[deploy] ERROR: health check failed after ${MAX_ATTEMPTS} attempts: ${HEALTH_URL}" >&2 + echo "[deploy] service status (wpp-staging.service):" >&2 + systemctl --no-pager --full status wpp-staging.service >&2 || true + echo "[deploy] recent service logs (wpp-staging.service):" >&2 + journalctl --no-pager -u wpp-staging.service -n 80 >&2 || true + exit 1 + fi + + echo "[deploy] health check not ready (attempt ${ATTEMPT}/${MAX_ATTEMPTS}); retrying in ${SLEEP_SECONDS}s" + sleep "${SLEEP_SECONDS}" + ATTEMPT=$((ATTEMPT + 1)) + if [ "${SLEEP_SECONDS}" -lt 8 ]; then + SLEEP_SECONDS=$((SLEEP_SECONDS * 2)) + fi +done + +echo "[deploy] health check passed: ${HEALTH_URL}" REMOTE echo "[deploy] OK: staging deploy complete for CT ${CT_ID} (${REF_NAME})"