Module shutdown

Module shutdown 

Source
Expand description

Graceful shutdown handling for ReasonKit Web server

This module provides comprehensive shutdown handling including:

  • Signal handling (SIGTERM, SIGINT)
  • Graceful connection draining
  • Systemd watchdog integration
  • Health status management during shutdown

§Architecture

Signal (SIGTERM/SIGINT)
        │
        ▼
┌───────────────────┐
│ ShutdownController│──────────▶ Notify all subscribers
└───────────────────┘
        │
        ▼
┌───────────────────┐
│ Stop new requests │
└───────────────────┘
        │
        ▼
┌───────────────────┐
│ Drain in-flight   │◀──── timeout: 30s default
└───────────────────┘
        │
        ▼
┌───────────────────┐
│ Flush logs        │
└───────────────────┘
        │
        ▼
┌───────────────────┐
│ Clean exit        │
└───────────────────┘

Modules§

axum_integration
Axum layer/middleware for graceful shutdown

Structs§

ConnectionGuard
RAII guard for tracking active connections
HealthStatus
Health check response during shutdown
ShutdownController
Shutdown controller that manages graceful shutdown

Enums§

ShutdownState
Shutdown state enum

Constants§

DEFAULT_DRAIN_TIMEOUT_SECS
Default drain timeout for in-flight requests
DEFAULT_SHUTDOWN_TIMEOUT_SECS
Default graceful shutdown timeout in seconds

Functions§

shutdown_signal
Create a shutdown signal future for use with Axum’s graceful shutdown
shutdown_signal_with_controller
Create a shutdown signal future with a controller for advanced shutdown handling
systemd_notify_readyLinux
Notify systemd that the service is ready
systemd_notify_statusLinux
Notify systemd with a status message
systemd_notify_stoppingLinux
Notify systemd that the service is stopping
systemd_watchdog_pingLinux
Send watchdog ping to systemd
watchdog_task
Watchdog task that periodically pings systemd