Files
mtusi2026lab6/scripts/stop-one.sh
T
dawuduk 14ab803529 Перенести рабочую реализацию lab5 в skeleton лабораторной 6.
API, worker, брокер и стенд остаются базой, контракт lab6 не менялся.
2026-11-17 15:15:42 +03:00

33 lines
868 B
Bash

#!/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