Files
mtusi2026lab4/scripts/stop-one.sh
2026-10-30 21:09:56 +03:00

25 lines
530 B
Bash
Executable File

#!/bin/sh
set -eu
# Failover hook: stop ONE API replica matching TARGET_INSTANCE_ID (hostname).
: "${TARGET_INSTANCE_ID:?TARGET_INSTANCE_ID is required}"
cd "$(dirname "$0")/.."
found=""
ids=$(docker compose --env-file .env ps -q api)
for id in $ids; do
host=$(docker inspect -f '{{.Config.Hostname}}' "$id")
if [ "$host" = "$TARGET_INSTANCE_ID" ]; then
found=$id
break
fi
done
if [ -z "$found" ]; then
echo "api replica not found" >&2
exit 1
fi
docker stop -t 8 "$found" >/dev/null
exit 0