solution
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#!/bin/sh
|
||||
# Restore the API service to 2 replicas after scripts/stop-one.sh.
|
||||
set -eu
|
||||
stack=${STACK_NAME:-lab5}
|
||||
service="${stack}_api"
|
||||
|
||||
# Swarm normally creates the replacement itself after stopping one task. This hook
|
||||
# restores the declared replica count and waits for two healthy tasks; a forced
|
||||
# rolling update is used only when the service is still under-replicated.
|
||||
docker service update --restart-condition any --replicas 2 "$service" >/dev/null
|
||||
running=$(docker service ps -q "$service" --filter desired-state=running | wc -l | tr -d ' ')
|
||||
if [ "$running" -lt 2 ]; then
|
||||
docker service update --force "$service" >/dev/null
|
||||
fi
|
||||
|
||||
i=0
|
||||
while [ "$i" -lt 60 ]; do
|
||||
running=$(docker service ps -q "$service" --filter desired-state=running | wc -l | tr -d ' ')
|
||||
if [ "$running" -ge 2 ] && curl -fsS http://127.0.0.1:8080/health/ready >/dev/null 2>&1; then
|
||||
printf 'api restored: %s running tasks and readiness OK\n' "$running"
|
||||
exit 0
|
||||
fi
|
||||
i=$((i + 1))
|
||||
sleep 2
|
||||
done
|
||||
printf 'api did not recover within 120s\n' >&2
|
||||
exit 1
|
||||
Reference in New Issue
Block a user