mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-17 21:45:41 +00:00
Handle SIGTERM for the docker containers + relay (#1735)
* Handle SIGTERM for some docker containers * Implement SIGTERM handling for the relay
This commit is contained in:
committed by
Bastian Köcher
parent
e47f1e42e0
commit
9495e1cfcb
@@ -16,6 +16,8 @@ log = "0.4.17"
|
|||||||
num-format = "0.4"
|
num-format = "0.4"
|
||||||
num-traits = "0.2"
|
num-traits = "0.2"
|
||||||
structopt = "0.3"
|
structopt = "0.3"
|
||||||
|
signal-hook = "0.3.14"
|
||||||
|
signal-hook-async-std = "0.2.2"
|
||||||
strum = { version = "0.21.0", features = ["derive"] }
|
strum = { version = "0.21.0", features = ["derive"] }
|
||||||
|
|
||||||
# Bridge dependencies
|
# Bridge dependencies
|
||||||
|
|||||||
@@ -18,7 +18,11 @@
|
|||||||
|
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
|
use async_std::prelude::*;
|
||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
|
use futures::{select, FutureExt};
|
||||||
|
use signal_hook::consts::*;
|
||||||
|
use signal_hook_async_std::Signals;
|
||||||
use structopt::{clap::arg_enum, StructOpt};
|
use structopt::{clap::arg_enum, StructOpt};
|
||||||
use strum::{EnumString, EnumVariantNames};
|
use strum::{EnumString, EnumVariantNames};
|
||||||
|
|
||||||
@@ -37,6 +41,9 @@ mod relay_messages;
|
|||||||
mod relay_parachains;
|
mod relay_parachains;
|
||||||
mod resubmit_transactions;
|
mod resubmit_transactions;
|
||||||
|
|
||||||
|
/// The target that will be used when publishing logs related to this pallet.
|
||||||
|
pub const LOG_TARGET: &str = "bridge";
|
||||||
|
|
||||||
/// Parse relay CLI args.
|
/// Parse relay CLI args.
|
||||||
pub fn parse_args() -> Command {
|
pub fn parse_args() -> Command {
|
||||||
Command::from_args()
|
Command::from_args()
|
||||||
@@ -100,8 +107,7 @@ impl Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Run the command.
|
/// Run the command.
|
||||||
pub async fn run(self) -> anyhow::Result<()> {
|
async fn do_run(self) -> anyhow::Result<()> {
|
||||||
self.init_logger();
|
|
||||||
match self {
|
match self {
|
||||||
Self::RelayHeaders(arg) => arg.run().await?,
|
Self::RelayHeaders(arg) => arg.run().await?,
|
||||||
Self::RelayMessages(arg) => arg.run().await?,
|
Self::RelayMessages(arg) => arg.run().await?,
|
||||||
@@ -114,6 +120,32 @@ impl Command {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Run the command.
|
||||||
|
pub async fn run(self) {
|
||||||
|
self.init_logger();
|
||||||
|
|
||||||
|
let exit_signals = match Signals::new([SIGINT, SIGTERM]) {
|
||||||
|
Ok(signals) => signals,
|
||||||
|
Err(e) => {
|
||||||
|
log::error!(target: LOG_TARGET, "Could not register exit signals: {}", e);
|
||||||
|
return
|
||||||
|
},
|
||||||
|
};
|
||||||
|
let run = self.do_run().fuse();
|
||||||
|
futures::pin_mut!(exit_signals, run);
|
||||||
|
|
||||||
|
select! {
|
||||||
|
signal = exit_signals.next().fuse() => {
|
||||||
|
log::info!(target: LOG_TARGET, "Received exit signal {:?}", signal);
|
||||||
|
},
|
||||||
|
result = run => {
|
||||||
|
if let Err(e) = result {
|
||||||
|
log::error!(target: LOG_TARGET, "substrate-relay: {}", e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_enum! {
|
arg_enum! {
|
||||||
|
|||||||
@@ -24,8 +24,5 @@ mod cli;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let command = cli::parse_args();
|
let command = cli::parse_args();
|
||||||
let run = command.run();
|
let run = command.run();
|
||||||
let result = async_std::task::block_on(run);
|
async_std::task::block_on(run);
|
||||||
if let Err(error) = result {
|
|
||||||
log::error!(target: "bridge", "substrate-relay: {}", error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user