16 lines
607 B
Bash
16 lines
607 B
Bash
#!/bin/sh
|
|
set -eu
|
|
target=${TARGET_INSTANCE_ID:?TARGET_INSTANCE_ID is required}
|
|
cd "$(dirname "$0")/.."
|
|
for service in api1 api2; do
|
|
for container in $(docker compose --env-file .env ps -q "$service"); do
|
|
instance=$(docker exec "$container" python -c 'import urllib.request; r=urllib.request.urlopen("http://127.0.0.1:8080/health/live",timeout=2); print(r.headers["X-Instance-Id"])' 2>/dev/null || true)
|
|
if [ "$instance" = "$target" ]; then
|
|
docker stop --time 5 "$container" >/dev/null
|
|
exit 0
|
|
fi
|
|
done
|
|
done
|
|
echo "No running API container matched TARGET_INSTANCE_ID" >&2
|
|
exit 1
|