Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Graceful shutdown #132

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions 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
Expand Up @@ -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"

Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 23 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,36 @@ mod test_utils;
mod util;

use clap::Parser;
use tracing::info;

use crate::util::Result;

#[tokio::main]
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)
}
Loading