Files

30 lines
860 B
Bash
Executable File
Raw Permalink 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.
#!/bin/sh
set -eu
# Поочерёдный рестарт API-реплик. Следующую не трогаем, пока текущая снова healthy.
ids=$(docker ps -q \
--filter label=com.docker.compose.project=mtusi-lab3 \
--filter label=com.docker.compose.service=api)
if [ -z "$ids" ]; then
echo "no api replicas" >&2
exit 1
fi
for id in $ids; do
docker restart --time 5 "$id" >/dev/null
i=0
while [ "$i" -lt 40 ]; do
status=$(docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}' "$id")
if [ "$status" = "healthy" ]; then
break
fi
i=$((i + 1))
sleep 1
done
if [ "$i" -ge 40 ]; then
echo "replica did not become healthy" >&2
exit 1
fi
# rise 2 у HAProxy: дать балансировщику вернуть реплику в ротацию.
sleep 2
done