forked from mtusi2026/mtusi2026lab3
29 lines
861 B
Bash
Executable File
29 lines
861 B
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
|
cd "$ROOT"
|
|
|
|
containers=$(docker compose ps -q api)
|
|
count=$(printf '%s\n' "$containers" | sed '/^$/d' | wc -l | tr -d ' ')
|
|
if [ "$count" -lt 2 ]; then
|
|
printf '%s\n' 'Rolling restart requires at least two API replicas' >&2
|
|
exit 1
|
|
fi
|
|
|
|
for container in $containers; do
|
|
docker restart --time 10 "$container" >/dev/null
|
|
deadline=$(( $(date +%s) + 60 ))
|
|
while :; do
|
|
status=$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' "$container")
|
|
if [ "$status" = healthy ]; then
|
|
break
|
|
fi
|
|
if [ "$status" = unhealthy ] || [ "$(date +%s)" -ge "$deadline" ]; then
|
|
printf '%s\n' "API replica did not become healthy: $container" >&2
|
|
exit 1
|
|
fi
|
|
sleep 1
|
|
done
|
|
done
|