From 34b69896e4330d111e9519d8f92c9125ff66c4e8 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 13 Dec 2022 23:03:04 +0100 Subject: [PATCH] Listen to SIGTERM in addition to ctrl-c for graceful shutdown --- crates/collab/k8s/environments/preview.sh | 2 +- crates/collab/src/main.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/collab/k8s/environments/preview.sh b/crates/collab/k8s/environments/preview.sh index ed037b0f0c..4d9dd849e9 100644 --- a/crates/collab/k8s/environments/preview.sh +++ b/crates/collab/k8s/environments/preview.sh @@ -1,3 +1,3 @@ ZED_ENVIRONMENT=preview -RUST_LOG=debug +RUST_LOG=info INVITE_LINK_PREFIX=https://zed.dev/invites/ diff --git a/crates/collab/src/main.rs b/crates/collab/src/main.rs index 63daed173b..1386df7157 100644 --- a/crates/collab/src/main.rs +++ b/crates/collab/src/main.rs @@ -7,6 +7,7 @@ use std::{ net::{SocketAddr, TcpListener}, path::Path, }; +use tokio::signal::unix::SignalKind; use tracing_log::LogTracer; use tracing_subscriber::{filter::EnvFilter, fmt::format::JsonFields, Layer}; use util::ResultExt; @@ -66,9 +67,15 @@ async fn main() -> Result<()> { axum::Server::from_tcp(listener)? .serve(app.into_make_service_with_connect_info::()) .with_graceful_shutdown(async move { - tokio::signal::ctrl_c() - .await + let mut sigterm = tokio::signal::unix::signal(SignalKind::terminate()) .expect("failed to listen for interrupt signal"); + let mut sigint = tokio::signal::unix::signal(SignalKind::interrupt()) + .expect("failed to listen for interrupt signal"); + let sigterm = sigterm.recv(); + let sigint = sigint.recv(); + futures::pin_mut!(sigterm); + futures::pin_mut!(sigint); + futures::future::select(sigterm, sigint).await; tracing::info!("Received interrupt signal"); rpc_server.teardown(); })