Files
mtusi2026lab3-fork/scripts/restart.sh
T
qrtx 676b38c18b feat(infra): add replicated API and readiness-aware load balancing
Provide resource profiles, persistent storage, parallel Nginx health checks and graceful restart hooks.
2026-10-29 11:46:56 +03:00

24 lines
828 B
Bash
Executable File

#!/bin/sh
set -eu
project_dir=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
cd "$project_dir"
for service in api nginx postgres redis; do
if [ -z "$(docker compose ps --all --quiet "$service")" ]; then
printf '%s\n' "Missing container for $service; start the Compose stack first." >&2
exit 1
fi
done
replicas=$(docker compose ps --all --quiet api | wc -l | tr -d ' ')
if [ "$replicas" -lt 1 ]; then
printf 'No API replicas found.\n' >&2
exit 1
fi
docker compose stop --timeout 30 nginx api postgres redis
docker compose up --detach --no-recreate --no-build --no-deps --wait --wait-timeout 45 postgres redis
docker compose up --detach --no-recreate --no-build --no-deps --scale "api=$replicas" --wait --wait-timeout 45 api
docker compose up --detach --no-recreate --no-build --no-deps nginx