Thanks to visit codestin.com
Credit goes to lib.rs

#server #graceful-shutdown #shutdown-signal #cancellation

sigterm

Signal-aware async control and cancellation primitives for Tokio

6 releases

Uses new Rust 2024

new 0.3.10 Jan 27, 2026
0.3.9 Jan 25, 2026

#760 in Asynchronous

MIT license

18KB
323 lines

Sigterm

Signal-aware async control and cancellation primitives for Tokio.

sigterm abstracts away the boilerplate of listening for system signals (Ctrl+C, SIGTERM, etc.) and coordinating shutdown across multiple asynchronous tasks.

Features

  • Signal Waiting: Wait for Ctrl+C or SIGTERM across platforms with a single await. Use try_wait() for non-panicking version.
  • Cancellation Tokens: Hierarchy-based cancellation (parent cancels child) powered by tokio-util.
  • Shutdown Primitives:
    • Shutdown: One-shot channel for single-task termination.
    • Broadcast: Notify multiple subscribers of a shutdown event.
    • ShutdownGuard: RAII guard that triggers shutdown when dropped (useful for panics).
  • Framework Integration: shutdown_signal() helper designed for seamless integration with axum::serve.
  • Unix Extensions: Listen for custom signal sets (SIGHUP, SIGQUIT, etc.) on Unix systems.

Usage Examples

Check the examples directory for runnable code:

Installation

[dependencies]
sigterm = { version = "0.3", features = ["full"] }

License

Released under the MIT License © 2026 Canmi

Dependencies

~0–2.7MB
~47K SLoC