forked from mtusi2026/mtusi2026lab2
Переносит минимум lab1 на PostgreSQL, добавляет Argon2id, Basic-вход, opaque Bearer-сессии в Valkey с TTL и AOF, строгую валидацию JSON, keyset-пагинацию по индексу, миграции, compose-стенд и собственные проверки уровня 3/4. Трек 5 — план запроса и восстановление.
43 lines
1.4 KiB
Bash
Executable File
43 lines
1.4 KiB
Bash
Executable File
#!/bin/sh
|
|
# Restart the API and every state store this lab uses, keeping the named
|
|
# volumes and all data. This is the hook for
|
|
# make test-persistence ACTION_SCRIPT=scripts/restart.sh
|
|
# It never removes volumes, never re-seeds and never prints credentials.
|
|
set -eu
|
|
cd "$(dirname "$0")/.."
|
|
|
|
if [ ! -f .env ]; then
|
|
echo "restart.sh: .env is missing; run make env first" >&2
|
|
exit 2
|
|
fi
|
|
if ! ./scripts/compose.sh --env-file .env ps --status running --quiet >/dev/null 2>&1; then
|
|
echo "restart.sh: compose stack is not available" >&2
|
|
exit 2
|
|
fi
|
|
|
|
wait_healthy() {
|
|
container=$1
|
|
attempts=0
|
|
while [ "$attempts" -lt 60 ]; do
|
|
status=$(docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' "$container" 2>/dev/null || echo missing)
|
|
if [ "$status" = "healthy" ] || [ "$status" = "running" ]; then
|
|
return 0
|
|
fi
|
|
attempts=$((attempts + 1))
|
|
sleep 1
|
|
done
|
|
echo "restart.sh: $container did not become healthy" >&2
|
|
return 1
|
|
}
|
|
|
|
echo "restart.sh: restarting postgres and valkey (volumes kept)"
|
|
./scripts/compose.sh --env-file .env restart postgres valkey
|
|
wait_healthy mtusi-lab2-melnikov-postgres
|
|
wait_healthy mtusi-lab2-melnikov-valkey
|
|
|
|
echo "restart.sh: restarting api (migrations re-applied idempotently)"
|
|
./scripts/compose.sh --env-file .env restart api
|
|
wait_healthy mtusi-lab2-melnikov-api
|
|
|
|
echo "restart.sh: all lab2 services restarted with volumes preserved"
|