Skip to content

Commit

Permalink
fix: gracefully shutdown on CTRL+C and SIGTERM (#273)
Browse files Browse the repository at this point in the history
Fixes #205
  • Loading branch information
internationalcrisis authored Feb 3, 2025
1 parent 5138667 commit bbe5f81
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit bbe5f81

Please sign in to comment.