Files
mtusi2026lab4/scripts/restore-one.sh
T
2026-12-01 22:01:52 +03:00

27 lines
833 B
Bash
Executable File

#!/bin/sh
# Восстанавливает остановленную API-реплику после failover-теста.
set -eu
ROOT=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
cd "$ROOT"
COMPOSE="docker compose -p gavrilenko-lab4 --env-file .env"
API_REPLICAS=$(grep -E '^API_REPLICAS=' .env | cut -d= -f2- || true)
API_REPLICAS=${API_REPLICAS:-2}
LB_PORT=$(grep -E '^LB_HOST_PORT=' .env | cut -d= -f2- || true)
LB_PORT=${LB_PORT:-8081}
$COMPOSE start api 2>/dev/null || true
$COMPOSE up -d --no-deps --scale "api=${API_REPLICAS}" api
deadline=$(( $(date +%s) + 90 ))
while :; do
if curl -fsS "http://127.0.0.1:${LB_PORT}/health/ready" >/dev/null 2>&1; then
exit 0
fi
if [ "$(date +%s)" -ge "$deadline" ]; then
echo "timeout waiting for api recovery" >&2
$COMPOSE ps >&2 || true
exit 1
fi
sleep 1
done