flybrain/infra/bin/wait-for-health
acamilo 660c3cf00d
Some checks failed
ci / node 22 (test + typecheck) (push) Has been cancelled
ci / rust stable (cargo test --workspace --release) (push) Has been cancelled
ci / infra/tests/lint.sh (push) Has been cancelled
ci / playwright apps/stage (allowed to fail) (push) Has been cancelled
flybrain v0.4.0: public tree (history retained privately)
2026-09-21 15:09:46 +00:00

31 lines
871 B
Bash
Executable file

#!/usr/bin/env bash
# infra/bin/wait-for-health URL TIMEOUT_SECONDS
#
# Poll a health endpoint until it returns 2xx, or exit 1 after
# TIMEOUT_SECONDS. Used as flystage's ExecStartPre against flysim's
# http://127.0.0.1:7401/healthz (docs/control-api.md: "200 when the loop
# advanced in the last 2 seconds, else 503").
set -euo pipefail
usage() { echo "usage: $0 URL TIMEOUT_SECONDS" >&2; exit 2; }
[ $# -eq 2 ] || usage
url="$1"
timeout="$2"
case "$timeout" in
''|*[!0-9]*) usage ;;
esac
deadline=$(( $(date +%s) + timeout ))
while true; do
code="$(curl -fsS -o /dev/null -w '%{http_code}' "$url" 2>/dev/null || true)"
case "$code" in
2??) exit 0 ;;
esac
if [ "$(date +%s)" -ge "$deadline" ]; then
echo "wait-for-health: $url not healthy after ${timeout}s (last code: ${code:-none})" >&2
exit 1
fi
sleep 0.5
done