#!/bin/sh # Stops exactly the API replica whose X-Instance-Id is TARGET_INSTANCE_ID and leaves it stopped. # X-Instance-Id = container hostname = first 12 hex chars of the container ID. # Restore afterwards: docker compose start api set -eu : "${TARGET_INSTANCE_ID:?test provides target API instance alias}" cd "$(dirname "$0")/.." case "$TARGET_INSTANCE_ID" in *[!0-9a-f]* | "") echo "unexpected instance id" >&2; exit 2 ;; esac ids=$(docker compose ps -q api | grep "^$TARGET_INSTANCE_ID" || true) [ "$(printf '%s\n' "$ids" | grep -c .)" -eq 1 ] || { echo "no single running api container for $TARGET_INSTANCE_ID" >&2; exit 1; } docker stop "$ids" >/dev/null # SIGTERM -> readiness 503 -> drain -> exit (about 3 s) echo "stopped $(docker inspect -f '{{.Name}}' "$ids") ($TARGET_INSTANCE_ID)"