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(()) }