Skip to content

armgit / kokon

Public Imported from GitHub
0

Edit photos by describing the change, on your own GPU. A free, open-source alternative to Nano Banana and ChatGPT image editing: photos stay on your computer, no daily limit. One installer for Windows, Mac and Linux sets up the best open model (Qwen-Image 2.1). MCP server for AI agents.

kokon-service: Ctrl+C and SIGTERM (docker stop, systemctl) shut down cleanly, stopping sd-server

Gabriele Lozupone0b8585fe0108
diff --git a/crates/qls-service/src/main.rs b/crates/qls-service/src/main.rs
index 06bc979..1a1f64e 100644
--- a/crates/qls-service/src/main.rs
+++ b/crates/qls-service/src/main.rs
@@ -311,6 +311,7 @@ async fn run(args: Vec<String>) {
tokio::spawn(lifecycle(state.clone()));
tokio::spawn(server_watch(state.clone()));
tokio::spawn(qls_core::engine_manifest::run(APP_VERSION));
+ tokio::spawn(stop_on_signal(state.clone()));
let app = api::router(state.clone(), false).into_make_service_with_connect_info::<SocketAddr>();
let st = state.clone();
@@ -339,6 +340,26 @@ async fn run(args: Vec<String>) {
tracing::info!("kokon-service exited");
}
+/// Ctrl+C in a terminal, `systemctl stop` or `docker stop` (SIGTERM): shut down like a client
+/// asking for it, so sd-server is stopped too instead of being left holding the GPU.
+async fn stop_on_signal(state: Arc<AppState>) {
+ #[cfg(unix)]
+ {
+ use tokio::signal::unix::{SignalKind, signal};
+ let Ok(mut term) = signal(SignalKind::terminate()) else { return };
+ tokio::select! {
+ _ = tokio::signal::ctrl_c() => {}
+ _ = term.recv() => {}
+ }
+ }
+ #[cfg(not(unix))]
+ if tokio::signal::ctrl_c().await.is_err() {
+ return;
+ }
+ tracing::info!("stop signal received — shutting down");
+ state.shutdown.notify_waiters();
+}
+
/// Exits when no client holds a lease, no job is pending, and the grace period passed.
/// Also unloads the model after long idle periods when no desktop window is attached.
async fn lifecycle(state: Arc<AppState>) {