Files
mtusi2026lab3/scripts/stop-one.sh
vest1ter cde3374d8a ЛР3: балансировка HAProxy, 2 реплики API, идемпотентность, отказоустойчивость (на 4)
- X-Instance-Id в каждом ответе; обязательный Idempotency-Key, таблица idempotency_keys
  (миграция 0002, одна транзакция, конкурентные повторы через уникальный индекс)
- graceful shutdown: SIGTERM -> ready=503 -> drain 3 с -> закрытие порта
- compose: lb (HAProxy) + api x2 без портов + разовый migrate + postgres, лимиты CPU/RAM
- хуки stop-one/restart/restore-replicas, scripts/experiments.py (failover, idempotency, rolling)
- свои тесты: 44 (13 новых); evidence: smoke, pytest, persistence, failover, эксперименты
2026-10-29 10:58:17 +03:00

22 lines
1.2 KiB
Bash
Raw Permalink 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
# Hook для make test-failover: остановить ОДНУ API-реплику и оставить её остановленной.
# TARGET_INSTANCE_ID = X-Instance-Id реплики = hostname контейнера = первые 12 символов его ID.
# БД, LB и volumes не трогаем. Вернуть реплику: scripts/restore-replicas.sh
set -eu
: "${TARGET_INSTANCE_ID:?test provides target API instance alias}"
case "$TARGET_INSTANCE_ID" in
""|*[!0-9a-f]*) echo "bad TARGET_INSTANCE_ID" >&2; exit 2 ;;
esac
# Только контейнер сервиса api нашего проекта: чужой/неизвестный ID не остановим.
container=$(docker ps -q \
--filter "label=com.docker.compose.project=mtusi-lab3" \
--filter "label=com.docker.compose.service=api" \
--filter "id=$TARGET_INSTANCE_ID")
[ -n "$container" ] || { echo "no running api container for the instance" >&2; exit 3; }
[ "$(printf '%s\n' "$container" | wc -l)" -eq 1 ] || { echo "ambiguous instance id" >&2; exit 4; }
# SIGTERM -> drain (3 с) -> завершение; -t 8: не дольше 8 с, чтобы уложиться в 10 с контракта теста.
docker stop -t 8 "$container" >/dev/null
echo "stopped $container"