From ee81e4f035713465b8af62d037aa5620cfc99df6 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 1 Apr 2023 14:44:56 +0200 Subject: [PATCH] fix: unix only sigterm (#2073) --- bin/reth/src/runner.rs | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/bin/reth/src/runner.rs b/bin/reth/src/runner.rs index e7cf78caec..065e840d12 100644 --- a/bin/reth/src/runner.rs +++ b/bin/reth/src/runner.rs @@ -3,7 +3,6 @@ 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 @@ -113,27 +112,39 @@ where Ok(tasks) } -/// Runs the future to completion or until a `ctrl-c` is received. +/// Runs the future to completion or until: +/// - `ctrl-c` is received. +/// - `SIGTERM` is received (unix only). async fn run_until_ctrl_c(fut: F) -> Result<(), E> where F: Future>, E: Send + Sync + 'static + From, { - let mut stream = tokio::signal::unix::signal(SignalKind::terminate())?; - let sigterm = stream.recv(); - let ctrl_c = tokio::signal::ctrl_c(); - pin_mut!(sigterm, ctrl_c, fut); + if cfg!(unix) { + let mut stream = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())?; + let sigterm = stream.recv(); + pin_mut!(sigterm, ctrl_c, fut); - tokio::select! { - _ = ctrl_c => { - trace!(target: "reth::cli", "Received ctrl-c"); - }, - _ = sigterm => { - trace!(target: "reth::cli", "Received SIGTERM"); - }, - res = fut => res?, + tokio::select! { + _ = ctrl_c => { + trace!(target: "reth::cli", "Received ctrl-c"); + }, + _ = sigterm => { + trace!(target: "reth::cli", "Received SIGTERM"); + }, + res = fut => res?, + } + } else { + pin_mut!(ctrl_c, fut); + + tokio::select! { + _ = ctrl_c => { + trace!(target: "reth::cli", "Received ctrl-c"); + }, + res = fut => res?, + } } Ok(())