Skip to content

Commit

Permalink
fix: gracefully shutdown on CTRL+C and SIGTERM
Browse files Browse the repository at this point in the history
  • Loading branch information
internationalcrisis committed Oct 1, 2024
1 parent e57eaa0 commit d8407ed
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 @@ -267,8 +267,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 = signal(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 d8407ed

Please sign in to comment.