Files
mtusi2026lab4/scripts/stop-one.sh
T
2026-10-20 15:13:41 +03:00

19 lines
492 B
Bash
Executable File

#!/bin/sh
set -eu
: "${TARGET_INSTANCE_ID:?test provides target API instance alias}"
cd "$(dirname "$0")/.."
for service in api-a api-b; do
container="$(docker compose ps -q "$service")"
[ -n "$container" ] || continue
hostname="$(docker inspect --format '{{.Config.Hostname}}' "$container")"
if [ "$hostname" = "$TARGET_INSTANCE_ID" ]; then
docker compose stop "$service"
exit 0
fi
done
printf '%s\n' 'TARGET_INSTANCE_ID does not match a running API replica' >&2
exit 2