#!/bin/sh set -eu cd "$(dirname "$0")/.." : "${TARGET_INSTANCE_ID:?Set TARGET_INSTANCE_ID to the observed API instance}" mkdir -p evidence for service in api1 api2; do instance=$(docker compose exec -T "$service" 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) || continue if [ "$instance" = "$TARGET_INSTANCE_ID" ]; then id=$(docker compose ps -q "$service") docker inspect --format '{{.Name}} {{.State.StartedAt}} {{.State.Status}}' "$id" > "evidence/stop-$service.txt" # SIGTERM, then bounded fallback. No automatic restart policy is enabled. docker compose stop -t 7 "$service" docker inspect --format '{{.Name}} {{.State.FinishedAt}} {{.State.Status}}' "$id" >> "evidence/stop-$service.txt" exit 0 fi done printf '%s\n' 'No running replica matches TARGET_INSTANCE_ID' >&2 exit 1