lab3
This commit is contained in:
+53
-6
@@ -1,11 +1,58 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
# Restart hook: bounce API replicas and every state store of the lab3 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)
|
||||
COMPOSE_BIN=${COMPOSE_BIN:-docker-compose}
|
||||
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
"$COMPOSE_BIN" -f docker-compose.local.yaml restart postgres redis
|
||||
"$COMPOSE_BIN" -f docker-compose.local.yaml up -d --wait postgres redis
|
||||
"$COMPOSE_BIN" -f docker-compose.local.yaml up -d --force-recreate api
|
||||
# .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: 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
|
||||
compose restart postgres redis
|
||||
compose up -d --wait postgres redis
|
||||
|
||||
# 2. API replicas: restart in place (same containers, same addresses) and bring
|
||||
# back any replica that was stopped by the fault-injection hook.
|
||||
compose restart api
|
||||
compose up -d --wait --no-deps api
|
||||
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user