Skip to content

Commit

Permalink
Exit on SIGTERM
Browse files Browse the repository at this point in the history
we currently only listen for SIGINT while k8s sends
a SIGTERM to shutdown a process, so we need to listen for that
too
  • Loading branch information
iffyio committed Sep 7, 2021
1 parent d2b0f7f commit af5f9bc
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down

0 comments on commit af5f9bc

Please sign in to comment.