diff options
author | Alex Auvolat <alex@adnab.me> | 2022-01-24 19:28:18 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-01-24 19:28:18 +0100 |
commit | 5e5299a6d0addc6498be12a24451860b9e4c3445 (patch) | |
tree | ee09ba8e40ae0e14af3dbe2ec4e576a6f0b4aea0 /src/http.rs | |
parent | d7511c683d47cdc6eb2d19f4276b359b1c6841f6 (diff) | |
download | tricot-5e5299a6d0addc6498be12a24451860b9e4c3445.tar.gz tricot-5e5299a6d0addc6498be12a24451860b9e4c3445.zip |
Add graceful shutdown and memory tracing
Diffstat (limited to 'src/http.rs')
-rw-r--r-- | src/http.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/http.rs b/src/http.rs index 05d7440..973e77f 100644 --- a/src/http.rs +++ b/src/http.rs @@ -4,6 +4,7 @@ use std::sync::Arc; use anyhow::Result; use log::*; +use futures::future::Future; use http::uri::Authority; use hyper::service::{make_service_fn, service_fn}; use hyper::{Body, Request, Response, Server, StatusCode, Uri}; @@ -12,7 +13,11 @@ use crate::consul::Consul; const CHALLENGE_PREFIX: &str = "/.well-known/acme-challenge/"; -pub async fn serve_http(bind_addr: SocketAddr, consul: Consul) -> Result<()> { +pub async fn serve_http( + bind_addr: SocketAddr, + consul: Consul, + shutdown_signal: impl Future<Output = ()>, +) -> Result<()> { let consul = Arc::new(consul); // For every connection, we must make a `Service` to handle all // incoming HTTP requests on said connection. @@ -30,7 +35,9 @@ pub async fn serve_http(bind_addr: SocketAddr, consul: Consul) -> Result<()> { }); info!("Listening on http://{}", bind_addr); - let server = Server::bind(&bind_addr).serve(make_svc); + let server = Server::bind(&bind_addr) + .serve(make_svc) + .with_graceful_shutdown(shutdown_signal); server.await?; |