Skip to content

armgit / kanzo

Public Imported from GitHub
0

Self-hosted, sharable kanban for humans and agents. One 4.7 MB binary, 5 MB of RAM, 10 to 60 tokens per agent reply, starts in 3 ms, zero setup.

Stop cleanly on SIGTERM

emanuele-emea70bcc3552f
diff --git a/src/web.rs b/src/web.rs
index 3e95d98..a5444b6 100644
--- a/src/web.rs
+++ b/src/web.rs
@@ -56,13 +56,34 @@ pub async fn serve(home: Home, port: Option<u16>, open: bool) -> Result<()> {
let shutdown = CancellationToken::new();
axum::serve(listener, router(home, guard, shutdown.clone()))
.with_graceful_shutdown(async move {
- let _ = tokio::signal::ctrl_c().await;
+ stop_signal().await;
shutdown.cancel();
})
.await?;
Ok(())
}
+/// Ctrl-C, or SIGTERM from launchd or systemd stopping the service.
+async fn stop_signal() {
+ #[cfg(unix)]
+ {
+ use tokio::signal::unix::{SignalKind, signal};
+ match signal(SignalKind::terminate()) {
+ Ok(mut term) => tokio::select! {
+ _ = tokio::signal::ctrl_c() => {}
+ _ = term.recv() => {}
+ },
+ Err(_) => {
+ let _ = tokio::signal::ctrl_c().await;
+ }
+ }
+ }
+ #[cfg(not(unix))]
+ {
+ let _ = tokio::signal::ctrl_c().await;
+ }
+}
+
fn router(home: Home, guard: Guard, shutdown: CancellationToken) -> Router {
let mut app = Router::new();
if home.config.mcp_http {