#!/bin/sh # Stop the single API replica whose X-Instance-Id is TARGET_INSTANCE_ID. # Leaves it stopped. Does not touch the database, Redis, the load balancer, or volumes. set -eu : "${TARGET_INSTANCE_ID:?test provides target API instance alias}" ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) cd "$ROOT" compose() { if [ -f .env ]; then docker compose --env-file .env "$@" else docker compose "$@" fi } found=0 for id in $(compose ps -q api); do iid=$(docker exec "$id" cat /tmp/instance-id 2>/dev/null | tr -d '\r\n' || true) host=$(docker inspect -f '{{.Config.Hostname}}' "$id") if [ "$iid" = "$TARGET_INSTANCE_ID" ] || [ "$host" = "$TARGET_INSTANCE_ID" ]; then docker stop -t 5 "$id" >/dev/null found=1 break fi done if [ "$found" -ne 1 ]; then echo "no running API replica matched TARGET_INSTANCE_ID" >&2 exit 1 fi