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

cli: unix: catch SIGTERM in addition to SIGINT and terminate gracefully #4463

Merged
merged 3 commits into from
Jul 7, 2021
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions neard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ openssl-probe = "0.1.2"
near-rust-allocator-proxy = { version = "0.2.8", optional = true }
lazy_static = "1.4"
tokio = "1.1"
futures = "0.3"

nearcore = { path = "../nearcore" }
near-primitives = { path = "../core/primitives" }
Expand Down
17 changes: 15 additions & 2 deletions neard/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::{DEFAULT_HOME, NEARD_VERSION, NEARD_VERSION_STRING, PROTOCOL_VERSION};
use clap::{AppSettings, Clap};
use futures::future::FutureExt;
use near_primitives::types::{Gas, NumSeats, NumShards};
use nearcore::get_store_path;
use std::net::SocketAddr;
Expand Down Expand Up @@ -263,8 +264,20 @@ impl RunCmd {
let sys = actix::System::new();
sys.block_on(async move {
nearcore::start_with_config(home_dir, near_config);
tokio::signal::ctrl_c().await.unwrap();
info!("Got Ctrl+C, stopping");

let sig = if cfg!(unix) {
use tokio::signal::unix::{signal, SignalKind};
let mut sigint = signal(SignalKind::interrupt()).unwrap();
let mut sigterm = signal(SignalKind::terminate()).unwrap();
futures::select! {
_ = sigint .recv().fuse() => "SIGINT",
_ = sigterm.recv().fuse() => "SIGTERM"
}
} else {
tokio::signal::ctrl_c().await.unwrap();
"Ctrl+C"
};
info!(target: "neard", "Got {}, stopping", sig);
actix::System::current().stop();
});
sys.run().unwrap();
Expand Down