forked from mtusi2026/mtusi2026lab3
21 lines
726 B
Bash
Executable File
21 lines
726 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
docker compose start api >/dev/null
|
|
deadline=$((SECONDS + 60))
|
|
while (( SECONDS < deadline )); do
|
|
healthy=0
|
|
for container_id in $(docker compose ps -q api); do
|
|
state=$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' "$container_id" 2>/dev/null || true)
|
|
[[ "$state" == healthy ]] && healthy=$((healthy + 1))
|
|
done
|
|
if (( healthy >= 2 )) && curl --fail --silent http://localhost:8080/health/ready >/dev/null; then
|
|
printf 'PASS: two API replicas are healthy through the load balancer.\n'
|
|
exit 0
|
|
fi
|
|
sleep 1
|
|
done
|
|
printf 'API replicas did not recover within 60 seconds.\n' >&2
|
|
docker compose ps
|
|
exit 1
|