aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-07-16 11:40:10 +0000
committerFuwn <[email protected]>2021-07-16 11:40:10 +0000
commitb15d6e0ed9af81bfd909408c0485f8dc79ac9ed8 (patch)
treeba95c6779cf6f4249c76d4dc07f11cbde39834b2
parentbuild(make): create kill task (diff)
downloadwhirl-b15d6e0ed9af81bfd909408c0485f8dc79ac9ed8.tar.xz
whirl-b15d6e0ed9af81bfd909408c0485f8dc79ac9ed8.zip
fix(cli): proper ctrl+c handling
-rw-r--r--crates/whirl/Cargo.toml1
-rw-r--r--crates/whirl/src/lib.rs12
2 files changed, 13 insertions, 0 deletions
diff --git a/crates/whirl/Cargo.toml b/crates/whirl/Cargo.toml
index 956620d..3cfca62 100644
--- a/crates/whirl/Cargo.toml
+++ b/crates/whirl/Cargo.toml
@@ -37,6 +37,7 @@ serde_derive = "1.0.126"
# CLI
structopt = "0.3.22"
+signal-hook = "0.3.9"
# Config
whirl_config = { path = "../whirl_config" }
diff --git a/crates/whirl/src/lib.rs b/crates/whirl/src/lib.rs
index 9297ccc..1e3931c 100644
--- a/crates/whirl/src/lib.rs
+++ b/crates/whirl/src/lib.rs
@@ -38,6 +38,7 @@ static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;
pub mod cli;
+use signal_hook::consts::{SIGINT, SIGTERM};
use whirl_config::Config;
pub struct Whirl;
@@ -78,6 +79,17 @@ impl Whirl {
}
}
+ // Ctrl+C handling
+ tokio::spawn(async move {
+ for signal in signal_hook::iterator::Signals::new(&[SIGTERM, SIGINT])
+ .unwrap()
+ .forever()
+ {
+ info!("signal received: {:?}, killing whirl", signal);
+ std::process::exit(0);
+ }
+ });
+
crate::cli::Cli::execute().await;
Ok(())