#!/bin/sh set -e for cid in $(docker compose ps -q api); do inst_id=$(docker exec "$cid" curl -s -i http://localhost:8000/health/live | grep -i "^x-instance-id:" | tr -d '\r' | awk '{print $2}') if [ -z "$TARGET_INSTANCE_ID" ] || [ "$inst_id" = "$TARGET_INSTANCE_ID" ]; then echo "Stopping container $cid (X-Instance-Id: $inst_id)" docker stop -t 2 "$cid" exit 0 fi done echo "Target replica not found" exit 1