ЛР 3 — БПИ2303 — Морару — на 5: API на TypeScript/Node, HAProxy, failover, трек 1

This commit is contained in:
celis
2026-10-29 20:59:24 +03:00
parent 0ab3a341aa
commit c4f9eb7648
83 changed files with 1862 additions and 19 deletions
+14
View File
@@ -0,0 +1,14 @@
#!/bin/sh
# Stops exactly the API replica whose X-Instance-Id is TARGET_INSTANCE_ID and leaves it stopped.
# X-Instance-Id = container hostname = first 12 hex chars of the container ID.
# Restore afterwards: docker compose start api
set -eu
: "${TARGET_INSTANCE_ID:?test provides target API instance alias}"
cd "$(dirname "$0")/.."
case "$TARGET_INSTANCE_ID" in
*[!0-9a-f]* | "") echo "unexpected instance id" >&2; exit 2 ;;
esac
ids=$(docker compose ps -q api | grep "^$TARGET_INSTANCE_ID" || true)
[ "$(printf '%s\n' "$ids" | grep -c .)" -eq 1 ] || { echo "no single running api container for $TARGET_INSTANCE_ID" >&2; exit 1; }
docker stop "$ids" >/dev/null # SIGTERM -> readiness 503 -> drain -> exit (about 3 s)
echo "stopped $(docker inspect -f '{{.Name}}' "$ids") ($TARGET_INSTANCE_ID)"