Files
mtusi2026lab3/scripts/stop-one.sh
T

17 lines
458 B
Bash
Executable File

#!/bin/sh
set -eu
: "${TARGET_INSTANCE_ID:?TARGET_INSTANCE_ID is required}"
cd "$(dirname "$0")/.."
for container_id in $(docker compose --env-file .env ps -q api); do
hostname=$(docker inspect --format '{{.Config.Hostname}}' "$container_id")
if [ "$hostname" = "$TARGET_INSTANCE_ID" ]; then
docker stop --timeout 5 "$container_id" >/dev/null
exit 0
fi
done
printf 'API replica %s not found\n' "$TARGET_INSTANCE_ID" >&2
exit 1