Files
mtusi2026lab4/scripts/stop-one.sh
T

23 lines
810 B
Bash
Executable File

#!/bin/sh
# Останавливает одну API-реплику и оставляет её остановленной.
# TARGET_INSTANCE_ID — значение X-Instance-Id (hostname контейнера).
set -eu
cd "$(dirname "$0")/.."
: "${TARGET_INSTANCE_ID:?TARGET_INSTANCE_ID is required}"
target=$(printf '%s' "$TARGET_INSTANCE_ID" | tr -d '[:space:]')
found=""
for id in $(docker compose --env-file .env ps -q api); do
host=$(docker inspect -f '{{.Config.Hostname}}' "$id")
full=$(docker inspect -f '{{.Id}}' "$id")
short=$(printf '%s' "$full" | cut -c1-12)
if [ "$host" = "$target" ] || [ "$short" = "$target" ] || [ "$full" = "$target" ]; then
found=$id
break
fi
done
if [ -z "$found" ]; then
echo "API replica not found" >&2
exit 1
fi
docker stop -t 8 "$found" >/dev/null