commit 92da9d71f8f0745b26c4dab654c6d5eabe6eb865
parent 6633f8b47254b9da16023d2761e36ce391e3a268
Author: Greg Heartsfield <scsibug@imap.cc>
Date: Wed, 28 Sep 2022 07:20:31 -0500
feat: handle and log TERM signals
Diffstat:
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/server.rs b/src/server.rs
@@ -150,9 +150,11 @@ async fn handle_web_request(
// return on a control-c or internally requested shutdown signal
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 {
tokio::select! {
- _ = shutdown_signal.recv() => {
+ _ = shutdown_signal.recv() => {
info!("Shutting down webserver as requested");
// server shutting down, exit loop
break;
@@ -160,7 +162,12 @@ async fn ctrl_c_or_signal(mut shutdown_signal: Receiver<()>) {
_ = tokio::signal::ctrl_c() => {
info!("Shutting down webserver due to SIGINT");
break;
- }
+ },
+ _ = term_signal.recv() => {
+ info!("Shutting down webserver due to SIGTERM");
+ break;
+ },
+
}
}
}