From af5f9bcda52baafd5a7030921d3ef911d98d1e5c Mon Sep 17 00:00:00 2001 From: ifeanyi Date: Tue, 7 Sep 2021 16:33:15 +0200 Subject: [PATCH] Exit on SIGTERM we currently only listen for SIGINT while k8s sends a SIGTERM to shutdown a process, so we need to listen for that too --- src/runner.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/runner.rs b/src/runner.rs index 4825ac2171..d42ebd8fbc 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -61,11 +61,26 @@ pub async fn run_with_config( .validate()? .build(); + #[cfg(target_os = "linux")] + let mut sig_term_fut = signal::unix::signal(signal::unix::SignalKind::terminate())?; + #[cfg(not(target_os = "linux"))] + let sig_term = std::future::pending(); + let (shutdown_tx, shutdown_rx) = watch::channel::<()>(()); + let signal_log = log.clone(); tokio::spawn(async move { + #[cfg(target_os = "linux")] + let sig_term = sig_term_fut.recv(); + tokio::select! { + _ = signal::ctrl_c() => { + info!(signal_log, "Received SIGINT") + } + _ = sig_term => { + info!(signal_log, "Received SIGTERM") + } + } // Don't unwrap in order to ensure that we execute // any subsequent shutdown tasks. - signal::ctrl_c().await.ok(); shutdown_tx.send(()).ok(); });