-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle SIGTERM properly #183
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,13 +11,19 @@ use hyper::{ | |
use hyper::{Body, Response, Server}; | ||
use tokio::net::TcpStream; | ||
use tokio_rustls::server::TlsStream; | ||
use tokio::signal::unix::SignalKind; | ||
|
||
pub struct WagiServer { | ||
routing_table: RoutingTable, | ||
tls: Option<TlsConfiguration>, | ||
address: SocketAddr, | ||
} | ||
|
||
async fn shutdown_signal() { | ||
// Wait for the SIGTERM signal | ||
tokio::signal::unix::signal(SignalKind::terminate()).unwrap().recv().await; | ||
} | ||
|
||
impl WagiServer { | ||
pub async fn new(configuration: &WagiConfiguration, routing_table: RoutingTable) -> anyhow::Result<Self> { | ||
Ok(Self { | ||
|
@@ -65,9 +71,10 @@ impl WagiServer { | |
})) | ||
}) | ||
}); | ||
Server::builder(tls::TlsHyperAcceptor::new(&self.address, &tls.cert_path, &tls.key_path).await?) | ||
.serve(mk_svc) | ||
.await?; | ||
let server = Server::builder(tls::TlsHyperAcceptor::new(&self.address, &tls.cert_path, &tls.key_path).await?) | ||
.serve(mk_svc); | ||
let graceful = server.with_graceful_shutdown(shutdown_signal()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We had problems with |
||
graceful.await?; | ||
}, | ||
None => { | ||
let mk_svc = make_service_fn(move |conn: &AddrStream| { | ||
|
@@ -80,7 +87,9 @@ impl WagiServer { | |
})) | ||
} | ||
}); | ||
Server::bind(&self.address).serve(mk_svc).await?; | ||
let server = Server::bind(&self.address).serve(mk_svc); | ||
let graceful = server.with_graceful_shutdown(shutdown_signal()); | ||
graceful.await?; | ||
}, | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this work on Windows? Might need to be conditionally compiled...