summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 2c0403e..9e49f29 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -388,6 +388,12 @@ impl App {
}
}
+async fn shutdown_signal() {
+ tokio::signal::ctrl_c()
+ .await
+ .expect("failed to install Ctrl+C signal handler");
+}
+
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let app = Arc::new(App::new());
@@ -403,7 +409,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
Err(std::env::VarError::NotUnicode(_)) => panic!("invalid encoding"),
};
- let server = Server::bind(&addr).serve(service);
+ let server = Server::bind(&addr)
+ .serve(service)
+ .with_graceful_shutdown(shutdown_signal());
println!("Listening on http://{}", addr);