#!/bin/sh set -eu : "${TARGET_INSTANCE_ID:?test provides target API instance alias}" SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) ROOT_DIR=$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd) cd "$ROOT_DIR" TARGET_CID="" for cid in $(docker compose --env-file .env ps -q api); do short_id=$(printf '%s' "$cid" | cut -c1-12) hostname_val=$(docker inspect -f '{{.Config.Hostname}}' "$cid" 2>/dev/null || true) if [ "$short_id" = "$TARGET_INSTANCE_ID" ] || [ "$cid" = "$TARGET_INSTANCE_ID" ] || [ "$hostname_val" = "$TARGET_INSTANCE_ID" ]; then TARGET_CID="$cid" break fi done if [ -z "$TARGET_CID" ]; then printf 'API container matching X-Instance-Id=%s not found\n' "$TARGET_INSTANCE_ID" >&2 exit 1 fi docker stop -t 5 "$TARGET_CID" >/dev/null