#!/bin/sh set -eu # Persistence hook: restart API and all state stores; keep volumes. cd "$(dirname "$0")/.." compose() { docker compose --env-file .env "$@" } deadline=$(( $(date +%s) + 70 )) wait_healthy() { svc=$1 want=1 if [ "$svc" = "api" ]; then want=${API_REPLICAS:-2} fi while [ "$(date +%s)" -lt "$deadline" ]; do states=$(compose ps "$svc" --format '{{.Health}}' || true) n=$(printf '%s\n' "$states" | grep -cx healthy || true) if [ "$n" -ge "$want" ]; then return 0 fi sleep 1 done echo "timed out waiting for $svc" >&2 return 1 } compose restart db cache minio wait_healthy db wait_healthy cache wait_healthy minio compose start api compose restart api wait_healthy api compose restart lb wait_healthy lb exit 0