Files
mtusi2026lab3-Chinyaeva/scripts/stop-one.sh

20 lines
700 B
Bash
Executable File

#!/bin/sh
# Stop exactly ONE API replica identified by the X-Instance-Id value supplied
# in TARGET_INSTANCE_ID. The container hostname is the instance id, so the
# mapping is deterministic and does not rely on container names.
# Leave the replica stopped; restore it explicitly after the test.
set -eu
cd "$(dirname "$0")/.."
target="${TARGET_INSTANCE_ID:?test provides target API instance alias}"
for id in $(docker compose --env-file .env ps -q api); do
host=$(docker inspect --format '{{.Config.Hostname}}' "$id")
if [ "$host" = "$target" ]; then
docker stop --time 1 "$id" >/dev/null
exit 0
fi
done
printf '%s\n' "target API replica not found: $target" >&2
exit 1