Files

17 lines
538 B
Bash

#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
: "${TARGET_INSTANCE_ID:?Set TARGET_INSTANCE_ID from a real API response}"
for id in $(docker compose ps -q api); do
host=$(docker inspect -f '{{.Config.Hostname}}' "$id")
case "$TARGET_INSTANCE_ID" in
"$host"-*)
printf 'Stopping API container %s (hostname %s)\n' "$id" "$host"
docker stop --time 5 "$id"
docker inspect -f '{{.Id}} {{.State.Status}}' "$id"
exit 0;;
esac
done
printf 'No running API matches target\n' >&2
exit 1