#!/bin/sh set -eu : "${TARGET_INSTANCE_ID:?test provides target API instance alias}" project_root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) cd "$project_root" env_file=${ENV_FILE:-.env} matched_container= for container_id in $(docker compose --env-file "$env_file" ps -a -q api); do instance_id=$(docker inspect --format '{{.Config.Hostname}}' "$container_id") if [ "$instance_id" = "$TARGET_INSTANCE_ID" ]; then if [ -n "$matched_container" ]; then printf '%s\n' "multiple API containers match instance $TARGET_INSTANCE_ID" >&2 exit 1 fi matched_container=$container_id fi done if [ -z "$matched_container" ]; then printf '%s\n' "API instance not found: $TARGET_INSTANCE_ID" >&2 exit 1 fi # A manual docker stop suppresses the container restart policy until the next # explicit start, so the selected replica remains down for the whole test. docker stop --time 5 "$matched_container" >/dev/null printf '%s\n' "stopped API instance $TARGET_INSTANCE_ID"