#!/bin/sh set -eu cd "$(dirname "$0")/.." if [ -f .env ]; then compose() { docker compose --env-file .env "$@"; } else : "${COMPOSE_PROJECT_NAME:?COMPOSE_PROJECT_NAME is required when .env is absent}" compose() { docker compose "$@"; } fi wait_healthy() { for service in "$@"; do containers=$(compose ps -q "$service") [ -n "$containers" ] || { echo "$service has no running containers" >&2; return 1; } for container in $containers; do attempts=0 until [ "$(docker inspect --format '{{.State.Health.Status}}' "$container")" = healthy ]; do attempts=$((attempts + 1)) [ "$attempts" -lt 30 ] || { echo "$service did not become healthy" >&2; return 1; } sleep 1 done done done } restart_services() { for service in "$@"; do containers=$(compose ps -a -q "$service") [ -n "$containers" ] || { echo "$service has no containers" >&2; return 1; } docker restart --timeout 20 $containers >/dev/null done } # Restart only long-running services and preserve their containers and volumes. cleanup=$(compose ps -a -q attachment-cleanup) [ -n "$cleanup" ] || { echo 'attachment-cleanup has no container' >&2; exit 1; } docker stop --timeout 20 "$cleanup" >/dev/null restart_services postgres redis s3 wait_healthy postgres redis s3 restart_services api wait_healthy api restart_services lb docker start "$cleanup" >/dev/null