Files
mtusi2026lab3/scripts/restore.sh
T

17 lines
788 B
Bash
Executable File

#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
case "${TARGET_INSTANCE_ID:-}" in api1|api2) ;; *) exit 2 ;; esac
id=$(docker compose --env-file .env ps -a -q "$TARGET_INSTANCE_ID")
test "$(docker inspect --format '{{.State.Running}}' "$id")" = false
for service in db lb api1 api2; do
test "$service" = "$TARGET_INSTANCE_ID" && continue
id=$(docker compose --env-file .env ps -q "$service")
test -n "$id"
test "$(docker inspect --format '{{.State.Running}}' "$id")" = true
done
echo "PASS: $TARGET_INSTANCE_ID really stopped; the other API, LB and database stayed running"
docker compose --env-file .env up -d --wait --wait-timeout 60 "$TARGET_INSTANCE_ID"
# Wait for HAProxy's next successful check; do not assume Compose health is LB health.
python3 scripts/wait_replicas.py