1use tracing::info;
4
5pub async fn wait_for_shutdown_signal() {
14 #[cfg(unix)]
15 {
16 use tokio::signal::unix::{signal, SignalKind};
17
18 let mut sigterm = signal(SignalKind::terminate()).expect("failed to install SIGTERM handler");
19
20 tokio::select! {
21 _ = tokio::signal::ctrl_c() => info!("Received SIGINT, shutting down..."),
22 _ = sigterm.recv() => info!("Received SIGTERM, shutting down..."),
23 }
24 }
25
26 #[cfg(windows)]
27 {
28 let mut ctrl_break = tokio::signal::windows::ctrl_break().expect("failed to install CTRL_BREAK handler");
29
30 tokio::select! {
31 _ = tokio::signal::ctrl_c() => info!("Received CTRL_C, shutting down..."),
32 _ = ctrl_break.recv() => info!("Received CTRL_BREAK, shutting down..."),
33 }
34 }
35
36 #[cfg(not(any(unix, windows)))]
37 {
38 let _ = tokio::signal::ctrl_c().await;
39
40 info!("Received SIGINT, shutting down...");
41 }
42}