Files
mtusi2026lab4/scripts/stop-one.sh
T

16 lines
422 B
Bash
Executable File

#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
: "${TARGET_INSTANCE_ID:?TARGET_INSTANCE_ID is required}"
for service in api1 api2; do
cid=$(docker compose ps -q "$service")
[ -n "$cid" ] || continue
hostname=$(docker inspect --format '{{.Config.Hostname}}' "$cid")
if [ "$hostname" = "$TARGET_INSTANCE_ID" ]; then
docker compose stop -t 2 "$service"
exit 0
fi
done
echo 'Target instance not found' >&2
exit 1