From aa5aaf816ff6ed7a0b2e2ca56bb61ee0322e9af3 Mon Sep 17 00:00:00 2001 From: Lyle Mantooth Date: Sun, 14 May 2023 22:51:25 -0400 Subject: [PATCH] Gracefully shutdown on SIGINT. --- src/main.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.rs b/src/main.rs index cf020b0..93e764b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,10 +46,16 @@ async fn main() { let app = Router::new().route("/", get(root_get)).with_state(state); + let quit_signal = async { + _ = tokio::signal::ctrl_c().await; + eprintln!("Initializing graceful shutdown"); + }; + let addr = "0.0.0.0:8080".parse().unwrap(); info!("Listening on {addr}"); axum::Server::bind(&addr) .serve(app.into_make_service()) + .with_graceful_shutdown(quit_signal) .await .unwrap(); }