Skip to main content

memvault_proxy/
shutdown.rs

1/// Waits for SIGINT (Ctrl+C) or SIGTERM, whichever comes first.
2/// Pass to `axum::serve(..).with_graceful_shutdown(shutdown_signal())`.
3pub async fn shutdown_signal() {
4    let ctrl_c = async {
5        tokio::signal::ctrl_c().await.ok();
6    };
7
8    #[cfg(unix)]
9    let terminate = async {
10        if let Ok(mut sig) =
11            tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
12        {
13            sig.recv().await;
14        }
15    };
16
17    #[cfg(not(unix))]
18    let terminate = std::future::pending::<()>();
19
20    tokio::select! {
21        _ = ctrl_c => tracing::info!("received Ctrl+C, shutting down"),
22        _ = terminate => tracing::info!("received SIGTERM, shutting down"),
23    }
24}