#!/bin/sh # Stop the API replica named by TARGET_INSTANCE_ID and leave it stopped. # Does not stop the database, Redis, the load balancer, or any volume. set -eu : "${TARGET_INSTANCE_ID:?test provides target API instance alias}" ROOT=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd) cd "$ROOT" found="" for cid in $(docker compose --env-file .env ps -q api); do host=$(docker inspect -f '{{.Config.Hostname}}' "$cid") short=$(docker inspect -f '{{.Id}}' "$cid" | cut -c1-12) name=$(docker inspect -f '{{.Name}}' "$cid" | sed 's#^/##') if [ "$host" = "$TARGET_INSTANCE_ID" ] || [ "$short" = "$TARGET_INSTANCE_ID" ] || [ "$name" = "$TARGET_INSTANCE_ID" ]; then found=$cid break fi done if [ -z "$found" ]; then echo "no running api container matches the instance" >&2 exit 1 fi docker stop -t 6 "$found" >/dev/null