feat: implement lab3 API load balancing and failover

This commit is contained in:
sashadugina06
2026-11-06 01:43:33 +03:00
parent 0ab3a341aa
commit 7088791d5c
116 changed files with 7971 additions and 38 deletions
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
: "${TARGET_INSTANCE_ID:?TARGET_INSTANCE_ID is required}"
found=''
for id in $(scripts/compose.sh ps -q api); do
actual=$(docker exec "$id" python -c 'import urllib.request; r=urllib.request.urlopen("http://127.0.0.1:8080/health/live",timeout=2); print(r.headers["X-Instance-Id"])')
if [ "$actual" = "$TARGET_INSTANCE_ID" ]; then
found="$id"
break
fi
done
[ -n "$found" ] || { echo 'No matching running API process' >&2; exit 1; }
printf 'Stopping API container %s instance %s\n' "$found" "$TARGET_INSTANCE_ID"
docker stop --timeout 6 "$found"