Files
ERP-core/deploy/scripts/wait-healthy.sh
T
ImanThiyanga 8e472ac996
CI/CD - ERP Core / scripts (pull_request) Failing after 12m21s
CI/CD - ERP Core / e2e-typecheck (pull_request) Failing after 13m13s
CI/CD - ERP Core / frontend (pull_request) Failing after 14m5s
CI/CD - ERP Core / backend (pull_request) Failing after 14m57s
CI/CD - ERP Core / detect (pull_request) Failing after 13m42s
CI/CD - ERP Core / Build & Deploy (pull_request) Failing after 12m47s
CI/CD - ERP Core / ci-ok (pull_request) Failing after 14m58s
initialising for ci-cd pipeline
2026-09-16 11:53:55 +05:30

38 lines
1.6 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# ci-cd.yml › Build & Deploy › Verify backend — wait until erpcore.service answers /health, and fail the job otherwise.
#
# EF migrations + seeding run BEFORE the app starts listening, so a slow start is normal. Only a
# crash (unit failed, or systemd auto-restarted it) or the ceiling counts as failure — a crashed
# service fails within seconds, and a slow but live migration is never cut short by a tight timer.
#
# Env: SERVICE (erpcore.service) · BACKEND_PORT (5220) · HEALTH_TIMEOUT seconds (300)
# RESTARTS_AT_START — NRestarts captured right after `systemctl start` (the Start step exports it)
set -euo pipefail
service="${SERVICE:-erpcore.service}"
port="${BACKEND_PORT:-5220}"
timeout="${HEALTH_TIMEOUT:-300}"
restarts_at_start="${RESTARTS_AT_START:-$(systemctl show -p NRestarts --value "$service")}"
show_journal() { journalctl -u "$service" -n 80 --no-pager || true; }
deadline=$((SECONDS + timeout))
while ((SECONDS < deadline)); do
if curl -fsS --max-time 5 -o /dev/null "http://127.0.0.1:$port/health" 2>/dev/null; then
echo "✅ $service is healthy (after ${SECONDS}s)"
exit 0
fi
state="$(systemctl show -p ActiveState --value "$service")"
restarts="$(systemctl show -p NRestarts --value "$service")"
if [[ "$state" == failed || "$restarts" != "$restarts_at_start" ]]; then
echo "❌ $service crashed during startup (state=$state, restarts $restarts_at_start → $restarts)" >&2
show_journal
exit 1
fi
sleep 3
done
echo "❌ $service did not answer /health within ${timeout}s (still starting? DB reachable?)" >&2
show_journal
exit 1