Files
mtusi2026lab7/scripts/restart.sh
T
Vladislav Kunetskiy 3d216fbd50 База lab7: контракт 1.7.0 и реализация lab1–lab6
Перенесены cmd/internal/config, compose.yaml, Dockerfile, скрипты, student-tests и evidence из mtusi-messenger (master, lab6). Skeleton lab7 (openapi/infrastructure 1.7.0, trust-matrix.md, security/THREAT_MODEL.md, infra/openbao, tests/security.py) сохранён; make test-security добавлен в Makefile.
2026-11-09 13:03:49 +03:00

59 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
set -eu
# Restart hook: bounce API replicas, worker/relay and every state store of the lab5 stand.
#
# scripts/restart.sh
#
# Persistent volumes are kept: no `down -v`, no flush, no re-seed. The one-shot
# `migrate` service is not re-run (schema stays as it is, data and sessions
# survive). The script exits 0 only after /health/ready answers through the LB.
# No credentials are printed.
ROOT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
cd "$ROOT_DIR"
# .env определяет, на каком порту публикуется LB (compose.yaml) и какие креды у
# хранилищ, поэтому значения берём оттуда же, а не из окружения вызывающего.
if [ -f .env ]; then
set -a
# shellcheck disable=SC1091
. ./.env
set +a
fi
COMPOSE_BIN=${COMPOSE_BIN:-docker compose}
PORT=${SERVER_PORT:-8080}
# shellcheck disable=SC2086
compose() {
# shellcheck disable=SC2086
$COMPOSE_BIN --env-file .env -f compose.yaml "$@"
}
# 1. State stores and broker: restart the running ones, then make sure they are
# healthy. Volumes are attached as before, nothing is dropped or re-seeded.
compose up -d --wait postgres redis seaweedfs broker
compose restart postgres redis seaweedfs broker
compose up -d --wait postgres redis seaweedfs broker
# 2. API replicas, worker and relay: restart in place and bring back any replica
# stopped by a fault-injection hook. The worker reconnects to the broker.
compose restart api worker relay
compose up -d --wait --no-deps api worker relay
# 3. Load balancer keeps its upstream; re-resolve in case addresses changed.
compose restart lb
# 4. Wait for readiness through the public entry point.
attempt=0
while [ "$attempt" -lt 60 ]; do
if curl -fsS --noproxy '*' -o /dev/null "http://127.0.0.1:${PORT}/health/ready"; then
printf 'restart.sh: stack restarted, http://127.0.0.1:%s/health/ready is ready\n' "$PORT"
exit 0
fi
attempt=$((attempt + 1))
sleep 1
done
printf 'restart.sh: /health/ready did not become ready through the LB\n' >&2
exit 1