#!/bin/sh # Crash-restart every persistent store after draining the application. # No re-seed or volume removal; the whole hook is bounded to 85 seconds. set -eu . "$(dirname "$0")/lib.sh" api=$(service_ids api); lb=$(service_ids lb); db=$(service_ids db) valkey=$(service_ids valkey); s3=$(service_ids s3); broker=$(service_ids broker) worker=$(service_ids worker); publisher=$(service_ids publisher) [ -n "$api" ] && [ -n "$db" ] && [ -n "$lb" ] && [ -n "$valkey" ] && [ -n "$s3" ] && [ -n "$broker" ] && [ -n "$worker" ] && [ -n "$publisher" ] || { echo "stack is not running" >&2; exit 2; } _restart_deadline=$(( $(date +%s) + 85 )) remaining() { _restart_left=$(( _restart_deadline - $(date +%s) )) [ "$_restart_left" -gt 0 ] || { echo "restart deadline exceeded" >&2; exit 1; } echo "$_restart_left" } echo "stopping lb + api + publisher + worker, then all stores" docker stop --time 10 $lb $api $publisher $worker >/dev/null # Deliberate crash, not a graceful shutdown of the stores. This tests that # confirmed data survives process death and avoids spending the public # hook's entire deadline on S3/RabbitMQ internal shutdown procedures. # Writers are stopped first; persistent volumes are kept unchanged. docker kill --signal KILL $db $valkey $s3 $broker >/dev/null echo "starting db + valkey + s3 + broker with existing volumes" docker start $db $valkey $s3 $broker >/dev/null wait_healthy "$(remaining)" $db $valkey $s3 $broker echo "starting publisher + worker + api" docker start $publisher $worker $api >/dev/null wait_healthy "$(remaining)" $api docker start $lb >/dev/null wait_healthy "$(remaining)" $lb echo "restart complete: PostgreSQL + Valkey + S3 + RabbitMQ + publisher + worker + API replicas + LB"