mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
fix: support graceful shutdown with SIGTERM (#2070)
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
use futures::pin_mut;
|
||||
use reth_tasks::{TaskExecutor, TaskManager};
|
||||
use std::future::Future;
|
||||
use tokio::signal::unix::SignalKind;
|
||||
use tracing::trace;
|
||||
|
||||
/// Used to execute cli commands
|
||||
@ -116,16 +117,23 @@ where
|
||||
async fn run_until_ctrl_c<F, E>(fut: F) -> Result<(), E>
|
||||
where
|
||||
F: Future<Output = Result<(), E>>,
|
||||
E: Send + Sync + 'static,
|
||||
E: Send + Sync + 'static + From<std::io::Error>,
|
||||
{
|
||||
let mut stream = tokio::signal::unix::signal(SignalKind::terminate())?;
|
||||
let sigterm = stream.recv();
|
||||
|
||||
let ctrl_c = tokio::signal::ctrl_c();
|
||||
|
||||
pin_mut!(ctrl_c, fut);
|
||||
pin_mut!(sigterm, fut);
|
||||
|
||||
tokio::select! {
|
||||
_ = ctrl_c => {
|
||||
trace!(target: "reth::cli", "Received ctrl-c");
|
||||
},
|
||||
_ = sigterm => {
|
||||
trace!(target: "reth::cli", "Received SIGTERM");
|
||||
},
|
||||
res = fut => res?,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user