Skip to content

Commit

Permalink
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 e6d4355
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![allow(dead_code)]

use tokio::signal::unix::{signal, SignalKind};

use brotli::enc::{BrotliCompress, BrotliEncoderParams};
use cached::proc_macro::cached;
use cookie::Cookie;
Expand Down Expand Up @@ -267,8 +269,13 @@ 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 {
// Wait for the CTRL+C signal
tokio::signal::ctrl_c().await.expect("Failed to install CTRL+C signal handler");
// Wait for the CTRL+C or SIGTERM
let mut signal_terminate = signal(SignalKind::terminate()).expect("Failed to install SIGTERM signal handler");

tokio::select! {
_ = signal_terminate.recv() => (),
_ = tokio::signal::ctrl_c() => ()
}
});

server.boxed()
Expand Down

0 comments on commit e6d4355

Please sign in to comment.