From 53e9c3d68add3a3856becf62077d753c96506d38 Mon Sep 17 00:00:00 2001 From: rkrishn7 Date: Thu, 7 Mar 2024 00:04:54 -0800 Subject: [PATCH] chore: register shutdown signal handlers --- src/kiwi/src/main.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/kiwi/src/main.rs b/src/kiwi/src/main.rs index e4f531f..5e35708 100644 --- a/src/kiwi/src/main.rs +++ b/src/kiwi/src/main.rs @@ -78,14 +78,27 @@ async fn main() -> anyhow::Result<()> { let listen_addr: SocketAddr = config.server.address.parse()?; - kiwi::ws::serve( - &listen_addr, - sources, - intercept, - authenticate, - config.subscriber, - ) - .await?; + #[cfg(windows)] + let mut term = tokio::signal::windows::ctrl_close().unwrap(); + #[cfg(unix)] + let mut term = + tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate()).unwrap(); + + tokio::select! { + _ = term.recv() => { + tracing::info!("Received SIGTERM, shutting down"); + } + _ = tokio::signal::ctrl_c() => { + tracing::info!("Received SIGINT, shutting down"); + } + _ = kiwi::ws::serve( + &listen_addr, + sources, + intercept, + authenticate, + config.subscriber, + ) => {} + } Ok(()) }