forked from mtusi2026/mtusi2026lab5
17 lines
660 B
Bash
Executable File
17 lines
660 B
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
cd "$(dirname "$0")/.."
|
|
|
|
: "${TARGET_INSTANCE_ID:?Set TARGET_INSTANCE_ID to the X-Instance-Id of an API replica}"
|
|
for container in $(docker compose --project-name highload-lab5 --env-file .env -f compose.yml ps -q api); do
|
|
hostname=$(docker inspect --format '{{.Config.Hostname}}' "$container")
|
|
if [ "$hostname" = "$TARGET_INSTANCE_ID" ]; then
|
|
# Only containers from this Compose project's api service are eligible.
|
|
docker stop --timeout 8 "$container" >/dev/null
|
|
printf 'Stopped API instance %s\n' "$hostname"
|
|
exit 0
|
|
fi
|
|
done
|
|
printf 'No running API replica matches TARGET_INSTANCE_ID\n' >&2
|
|
exit 1
|