Skip to content

Commit

Permalink
Add Ctrl-C support
Browse files Browse the repository at this point in the history
When we run the docker container, it currently can't be killed with a ctrl-c. This commit
adds in support to capture that signal and exit, rather than just ignoring it as we do now
  • Loading branch information
sinkingpoint committed Jul 11, 2022
1 parent 317e285 commit 287cd5a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gravel-gateway"
version = "1.4.0"
version = "1.5.1"
edition = "2018"
license = "LGPL-3.0"
description = "A Prometheus Push Gateway for FAAS applications"
Expand Down
28 changes: 19 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ mod clustering;
mod aggregator_test;
mod auth;

use tokio::signal;

#[tokio::main]
async fn main() {
let agg = Aggregator::new();
Expand Down Expand Up @@ -181,19 +183,27 @@ async fn main() {
if let Some(tls_key) = matches.value_of("tls-key") {
// Clap ensures that if one of these exists, so does the other
let tls_cert = matches.value_of("tls-cert").unwrap();
tokio::join!(futures::future::join_all(address
.into_iter()
.map(move |addr| warp::serve(routes.clone()).tls().key_path(tls_key).cert_path(tls_cert).run(addr))));

tokio::select! {
_ = signal::ctrl_c() => {},

_ = futures::future::join_all(address.into_iter()
.map(move |addr| warp::serve(routes.clone()).tls().key_path(tls_key).cert_path(tls_cert).run(addr))) => {}
};
}
else {
tokio::join!(futures::future::join_all(address
.into_iter()
.map(move |addr| warp::serve(routes.clone()).run(addr))));
tokio::select! {
_ = signal::ctrl_c() => {},

_ = futures::future::join_all(address.into_iter()
.map(move |addr| warp::serve(routes.clone()).run(addr))) => {}
};
};

// If we don't have TLS support, just bind without it
#[cfg(not(feature="tls"))]
tokio::join!(futures::future::join_all(address
.into_iter()
.map(move |addr| warp::serve(routes.clone()).run(addr))));
tokio::select! {
_ = signal::ctrl_c() => {}
_ = futures::future::join_all(address.into_iter().map(move |addr| warp::serve(routes.clone()).run(addr))) => {}
};
}

0 comments on commit 287cd5a

Please sign in to comment.