Graceful Shutdown
When your server receives a termination signal (Ctrl+C,kill, Docker stop), you don’t want to drop active requests. PrismGracefulShutdown catches signals, runs cleanup hooks, and rejects new requests while in-flight ones finish.
Quick Setup
Enable Graceful Shutdown
Shutdown Middleware
Reject new requests during shutdown with a503 Service Unavailable:
Reject During Shutdown
- Status:
503 Service Unavailable - Header:
Connection: close - Header:
Retry-After: 5 - Body:
"Server is shutting down"
How It Works
- Signal received — SIGTERM or SIGINT caught by DispatchSource
- Shutdown begins —
isShuttingDownflag set, new requests rejected - Hooks run — Each registered
onShutdownhandler runs in order - Final shutdown — The closure passed to
installSignalHandlersruns last
Practical Example
Full Shutdown Setup
Checking Shutdown State
Check State
Manual Shutdown
Trigger shutdown programmatically (e.g., from an admin endpoint):Admin Shutdown