Files
mtusi2026lab5/scripts/restart.sh
T
2026-11-20 20:11:39 +03:00

27 lines
1013 B
Bash

#!/bin/sh
# Restart API and every state store without deleting volumes.
#
# Used by make test-persistence. Sessions live in Valkey with AOF and users,
# chats and messages in PostgreSQL, so the same bearer token and data survive.
set -eu
stack=${STACK_NAME:-lab5}
ready_url=${READY_URL:-http://127.0.0.1:8080/health/ready}
for service in "${stack}_postgres" "${stack}_valkey" "${stack}_minio" "${stack}_rabbitmq" \
"${stack}_relay" "${stack}_worker" "${stack}_api" "${stack}_traefik"; do
printf 'restarting %s\n' "$service"
# detach: не ждём сходимости каждого сервиса; готовность проверяется один раз ниже.
docker service update --detach=true --force "$service" >/dev/null
done
i=0
while [ "$i" -lt 60 ]; do
if curl -fsS "$ready_url" >/dev/null 2>&1; then
printf 'stack ready after restart\n'
exit 0
fi
i=$((i + 1))
sleep 2
done
printf 'stack did not become ready within 120s\n' >&2
exit 1