forked from mtusi2026/mtusi2026lab4
15 lines
531 B
Bash
Executable File
15 lines
531 B
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
: "${TARGET_INSTANCE_ID:?TARGET_INSTANCE_ID is required}"
|
|
# X-Instance-Id is the container hostname (the Docker short ID). Resolve it to
|
|
# exactly one scaled Compose container and stop only that process.
|
|
for id in $(docker compose --env-file .env ps -q api); do
|
|
hostname=$(docker inspect --format '{{.Config.Hostname}}' "$id")
|
|
if [ "$hostname" = "$TARGET_INSTANCE_ID" ]; then
|
|
docker stop --time 3 "$id" >/dev/null
|
|
exit 0
|
|
fi
|
|
done
|
|
echo "No running api container matches TARGET_INSTANCE_ID" >&2
|
|
exit 1
|