Files
mtusi2026lab3/scripts/stop-one.sh
T

16 lines
1.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# Останавливает РОВНО ОДНУ API-реплику: ту, чей X-Instance-Id (= hostname контейнера) передан в
# TARGET_INSTANCE_ID, и оставляет её остановленной. БД, LB и volumes не трогаются. Секреты не печатаются.
# Восстановление отдельно: docker compose up -d (или scripts/start-all.sh)
set -eu
: "${TARGET_INSTANCE_ID:?test provides target API instance alias}"
case "$TARGET_INSTANCE_ID" in
*[!A-Za-z0-9._-]*|"") echo "bad instance id" >&2; exit 2 ;;
esac
cd "$(dirname "$0")/.."
# Фильтр по compose-сервису api: LB/БД остановить этим скриптом невозможно.
cid=$(docker ps -q --filter "id=$TARGET_INSTANCE_ID" --filter "label=com.docker.compose.service=api" | head -n 1)
[ -n "$cid" ] || { echo "api container for instance not found" >&2; exit 1; }
# SIGTERM → graceful shutdown (ready=503, drain, закрытие listener); через 5 с — SIGKILL.
docker stop --time 5 "$cid" >/dev/null