forked from mtusi2026/mtusi2026lab4
lab4 - оценка 4
This commit is contained in:
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
echo "Restarting stateful services and API without removing volumes ..."
|
||||
docker compose --env-file .env restart postgres redis s3 api lb
|
||||
|
||||
echo "waiting for readiness ..."
|
||||
|
||||
i=0
|
||||
while true; do
|
||||
i=$((i + 1))
|
||||
|
||||
if curl -fsS http://localhost:8080/health/ready >/dev/null 2>&1; then
|
||||
echo "ready"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$i" -ge 90 ]; then
|
||||
echo "API did not become ready in time" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
done
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
BASE="${BASE_URL:-http://localhost:8080}"
|
||||
|
||||
RUNNING=$(docker ps --filter "label=com.docker.compose.service=api" --filter "status=running" -q)
|
||||
COUNT=$(printf '%s\n' "$RUNNING" | grep -c . || true)
|
||||
if [ "$COUNT" -lt 2 ]; then
|
||||
echo "need >=2 running api replicas, found $COUNT" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TARGET=$(curl -s -D - -o /dev/null "$BASE/health/live" \
|
||||
| tr -d '\r' \
|
||||
| awk 'tolower($1)=="x-instance-id:"{print $2}')
|
||||
|
||||
if [ -z "$TARGET" ]; then
|
||||
echo "could not observe X-Instance-Id via LB" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! printf '%s\n' "$RUNNING" | grep -qi "^${TARGET}"; then
|
||||
CID=$(docker inspect --format '{{.Id}} {{.Config.Hostname}}' $RUNNING \
|
||||
| awk -v t="$TARGET" '$2==t{print substr($1,1,12)}' | head -n 1)
|
||||
[ -n "$CID" ] || { echo "target $TARGET not a running api replica" >&2; exit 1; }
|
||||
TARGET="$CID"
|
||||
fi
|
||||
|
||||
echo "stopping LB-observed replica $TARGET ..." >&2
|
||||
docker stop -t 10 "$TARGET" >/dev/null
|
||||
echo "stopped $TARGET" >&2
|
||||
Reference in New Issue
Block a user