feat: handle and log TERM signals

This commit is contained in:
Greg Heartsfield 2022-09-28 07:20:31 -05:00
parent 6633f8b472
commit 92da9d71f8

View File

@ -150,9 +150,11 @@ async fn handle_web_request(
// return on a control-c or internally requested shutdown signal // return on a control-c or internally requested shutdown signal
async fn ctrl_c_or_signal(mut shutdown_signal: Receiver<()>) { async fn ctrl_c_or_signal(mut shutdown_signal: Receiver<()>) {
let mut term_signal = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
.expect("could not define signal");
loop { loop {
tokio::select! { tokio::select! {
_ = shutdown_signal.recv() => { _ = shutdown_signal.recv() => {
info!("Shutting down webserver as requested"); info!("Shutting down webserver as requested");
// server shutting down, exit loop // server shutting down, exit loop
break; break;
@ -160,7 +162,12 @@ async fn ctrl_c_or_signal(mut shutdown_signal: Receiver<()>) {
_ = tokio::signal::ctrl_c() => { _ = tokio::signal::ctrl_c() => {
info!("Shutting down webserver due to SIGINT"); info!("Shutting down webserver due to SIGINT");
break; break;
} },
_ = term_signal.recv() => {
info!("Shutting down webserver due to SIGTERM");
break;
},
} }
} }
} }