Gracefully shutdown on SIGINT.

This commit is contained in:
Lyle Mantooth 2023-05-14 22:51:25 -04:00
parent 460c002145
commit aa5aaf816f
Signed by: IslandUsurper
GPG key ID: 6DB52EAE123A5789

View file

@ -46,10 +46,16 @@ async fn main() {
let app = Router::new().route("/", get(root_get)).with_state(state); 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(); let addr = "0.0.0.0:8080".parse().unwrap();
info!("Listening on {addr}"); info!("Listening on {addr}");
axum::Server::bind(&addr) axum::Server::bind(&addr)
.serve(app.into_make_service()) .serve(app.into_make_service())
.with_graceful_shutdown(quit_signal)
.await .await
.unwrap(); .unwrap();
} }