#!/bin/sh # Hook for: make test-failover ACTION_SCRIPT=scripts/stop-one.sh # Stops exactly ONE API replica and leaves it stopped. TARGET_INSTANCE_ID is the X-Instance-Id # of the replica, which is its container hostname = short container ID. The hook checks that # the ID belongs to a running "api" container of this compose project before stopping it. # docker stop sends SIGTERM: the replica reports not ready, HAProxy removes it, then it exits. # Restore afterwards: docker compose up -d (or docker start ) set -eu : "${TARGET_INSTANCE_ID:?test provides target API instance alias}" cd "$(dirname "$0")/.." project="${COMPOSE_PROJECT_NAME:-mtusi-lab3}" id=$(docker ps -q --filter "id=$TARGET_INSTANCE_ID" \ --filter "label=com.docker.compose.project=$project" \ --filter "label=com.docker.compose.service=api") if [ -z "$id" ]; then echo "TARGET_INSTANCE_ID is not a running api replica of $project" >&2 exit 1 fi docker stop "$id" >/dev/null