forked from mtusi2026/mtusi2026lab3
- compose: один масштабируемый сервис api (deploy.replicas=2, без ports и container_name), HAProxy 3.2 LTS по digest — единственная точка входа (127.0.0.1), разовый migrate до старта реплик, CPU/RAM-лимиты у всех сервисов, каждому сервису только его secrets. - HAProxy: server-template + Docker DNS (re-resolve 1 с), активная проверка GET /health/ready каждую 1 с (fall 2 / rise 2), без backup-серверов, retry только conn-failure, ошибки самого LB — в формате контракта с X-Request-Id. - API: X-Instance-Id = hostname контейнера на каждом ответе (и на 500/503); Idempotency-Key обязателен; ключ, сообщение и результат пишутся в ОДНОЙ транзакции (миграция 0002), конкурентный повтор ждёт уникальный индекс; другой body — 409, посторонний — всегда 404; attachment_ids=[] равен отсутствию поля; дубли ключей JSON и тело у POST /auth/sessions — 400. - SIGTERM: readiness 503 + DRAIN_SECONDS=3 обслуживания, затем graceful stop. - scripts: stop-one.sh (+ .cmd для Windows), restore-api.sh, restart.sh перезапускает и LB, lbctl.py — состояние бэкендов HAProxy -> контейнеры. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
18 lines
916 B
Bash
Executable File
18 lines
916 B
Bash
Executable File
#!/bin/sh
|
|
# Restart hook for `make test-persistence ACTION_SCRIPT=scripts/restart.sh`.
|
|
# Restarts EVERY process of the stand: LB, all API replicas, PostgreSQL and Valkey.
|
|
# Volumes, schema and data are preserved: no `down -v`, no FLUSH, no re-seed.
|
|
# Output is suppressed by the test; run it by hand to see the steps.
|
|
set -eu
|
|
cd "$(dirname "$0")/.."
|
|
|
|
# 1. Entry point and API first: no request is served while the stores restart underneath.
|
|
docker compose stop lb api
|
|
# 2. Stores: clean shutdown (PostgreSQL checkpoint, Valkey AOF fsync), then start again.
|
|
docker compose restart postgres valkey
|
|
# 3. API replicas (wait for healthy stores via depends_on), then the LB. HAProxy resolves
|
|
# the new replica addresses through Docker DNS by itself - no stale backend list.
|
|
docker compose start api
|
|
docker compose start lb
|
|
echo "restart.sh: lb, api (all replicas), postgres and valkey restarted with volumes preserved"
|