Files
mtusi2026lab3/scripts/restart.sh
T
2026-10-23 16:38:27 +03:00

39 lines
732 B
Bash
Executable File

#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
compose() {
docker compose --env-file .env "$@"
}
deadline=$(( $(date +%s) + 70 ))
wait_healthy() {
svc=$1
want=1
if [ "$svc" = "api" ]; then
want=${API_REPLICAS:-2}
fi
while [ "$(date +%s)" -lt "$deadline" ]; do
states=$(compose ps "$svc" --format '{{.Health}}' || true)
n=$(printf '%s\n' "$states" | grep -cx healthy || true)
if [ "$n" -ge "$want" ]; then
return 0
fi
sleep 1
done
echo "timed out waiting for $svc" >&2
return 1
}
compose restart db cache
wait_healthy db
wait_healthy cache
compose start api
compose restart api
wait_healthy api
compose restart lb
wait_healthy lb
exit 0