diff --git a/Cargo.lock b/Cargo.lock index 982b75c..0a52990 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2529,6 +2529,15 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + [[package]] name = "siphasher" version = "0.3.11" @@ -2749,6 +2758,7 @@ dependencies = [ "mio", "num_cpus", "pin-project-lite", + "signal-hook-registry", "socket2", "tokio-macros", "windows-sys 0.48.0", diff --git a/Cargo.toml b/Cargo.toml index 531cc8c..3235f93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ thiserror = "1.0.57" futures = "0.3.30" itertools = "0.12.1" paste = "1.0.14" -tokio = { version = "1.36.0", features = ["macros", "net", "rt-multi-thread", "sync"] } +tokio = { version = "1.36.0", features = ["macros", "net", "rt-multi-thread", "sync", "signal"] } lazy_static = "1.4.0" blake3 = "1.5.1" diff --git a/Makefile b/Makefile index ba5503a..e79a705 100644 --- a/Makefile +++ b/Makefile @@ -18,13 +18,17 @@ SOURCES := $(wildcard **/*.rs) Cargo.toml Cargo.lock $(IMAGE_NAME)\:nightly \ push-manifest-$(VERSION) \ push-manifest-latest \ - push-manifest-nightly + push-manifest-nightly \ + print-version # The following rules are skipped because "The implicit rule search (see Implicit Rules) is skipped for .PHONY targets." # $(foreach target,$(TARGETS),$(IMAGE_NAME)\:$(VERSION)-$(target)) \ # $(foreach target,$(TARGETS),$(IMAGE_NAME)\:latest-$(target)) \ # $(foreach target,$(TARGETS),push-docker-$(VERSION)-$(target)) \ +print-version: + @echo $(IMAGE_NAME):$(VERSION) + inspector-assets: cd inspector && pnpm install && pnpm build diff --git a/src/main.rs b/src/main.rs index 95642e7..d67d9ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ mod test_utils; mod util; use clap::Parser; +use tracing::info; use crate::util::Result; @@ -22,6 +23,28 @@ use crate::util::Result; async fn main() -> Result<()> { tracing_subscriber::fmt::init(); + tokio::spawn(async { + signal_handler().await.expect("Signal handler failed"); + }); + let cli = cli::Cli::parse(); cli.run().await } + +async fn signal_handler() -> Result<()> { + use tokio::signal::unix::{signal, SignalKind}; + + let mut sigint = signal(SignalKind::interrupt())?; + let mut sigterm = signal(SignalKind::terminate())?; + + tokio::select! { + _ = sigint.recv() => { + info!("Received SIGINT, shutting down..."); + } + _ = sigterm.recv() => { + info!("Received SIGTERM, shutting down..."); + } + }; + + std::process::exit(0) +}