feat: implement lab3 API load balancing and failover
This commit is contained in:
Executable
+15
@@ -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"
|
||||
Reference in New Issue
Block a user