fix: gracefully shutdown on CTRL+C and SIGTERM (#273)

Fixes #205
This commit is contained in:
internationalcrisis 2025-02-02 22:40:19 -06:00 committed by GitHub
parent 51386671d3
commit bbe5f81914
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -282,8 +282,19 @@ impl Server {
// Bind server to address specified above. Gracefully shut down if CTRL+C is pressed
let server = HyperServer::bind(address).serve(make_svc).with_graceful_shutdown(async {
#[cfg(windows)]
// Wait for the CTRL+C signal
tokio::signal::ctrl_c().await.expect("Failed to install CTRL+C signal handler");
#[cfg(unix)]
{
// Wait for CTRL+C or SIGTERM signals
let mut signal_terminate = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate()).expect("Failed to install SIGTERM signal handler");
tokio::select! {
_ = tokio::signal::ctrl_c() => (),
_ = signal_terminate.recv() => ()
}
}
});
server.boxed()