summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuomas Siipola2021-04-15 11:13:53 +0300
committerTuomas Siipola2021-04-15 11:15:24 +0300
commit9670b8f5ddbd47fb44c2e1b58f11d27e64115bb1 (patch)
treee0f7d3f75f6c26cd706e880b4717ee618d097f6d
parentc2458f8536c99ad5fc46a93532e914ef89dde37a (diff)
Add graceful shutdownHEADmaster
-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);