b473aeb3be
* task dependency * unifying some startup code and passing TaskClient around * graceful shutdown handling for mix socket listener * graceful shutdown handling for clients listener * graceful shutdown handling for packet forwarding * unified waiting for interrupt across binaries * made 'validate_bech32_address_or_exit' into a function that returns proper Result * printing formatted message on main error * fixed failing test * removed duplicate code that should have been gone ages ago * ibid * removed biased selection for authenticated handler * minor refactoring to 'ensure_config_version_compatibility'
72 lines
2.0 KiB
Rust
72 lines
2.0 KiB
Rust
use crate::{manager::SentError, TaskManager};
|
|
|
|
#[cfg(unix)]
|
|
#[deprecated]
|
|
pub async fn wait_for_signal() {
|
|
use tokio::signal::unix::{signal, SignalKind};
|
|
let mut sigterm = signal(SignalKind::terminate()).expect("Failed to setup SIGTERM channel");
|
|
let mut sigquit = signal(SignalKind::quit()).expect("Failed to setup SIGQUIT channel");
|
|
|
|
tokio::select! {
|
|
_ = tokio::signal::ctrl_c() => {
|
|
log::info!("Received SIGINT");
|
|
},
|
|
_ = sigterm.recv() => {
|
|
log::info!("Received SIGTERM");
|
|
}
|
|
_ = sigquit.recv() => {
|
|
log::info!("Received SIGQUIT");
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(not(unix))]
|
|
pub async fn wait_for_signal() {
|
|
tokio::select! {
|
|
_ = tokio::signal::ctrl_c() => {
|
|
log::info!("Received SIGINT");
|
|
},
|
|
}
|
|
}
|
|
|
|
#[cfg(unix)]
|
|
pub async fn wait_for_signal_and_error(shutdown: &mut TaskManager) -> Result<(), SentError> {
|
|
use tokio::signal::unix::{signal, SignalKind};
|
|
|
|
let mut sigterm = signal(SignalKind::terminate()).expect("Failed to setup SIGTERM channel");
|
|
let mut sigquit = signal(SignalKind::quit()).expect("Failed to setup SIGQUIT channel");
|
|
|
|
tokio::select! {
|
|
_ = tokio::signal::ctrl_c() => {
|
|
log::info!("Received SIGINT");
|
|
Ok(())
|
|
},
|
|
_ = sigterm.recv() => {
|
|
log::info!("Received SIGTERM");
|
|
Ok(())
|
|
}
|
|
_ = sigquit.recv() => {
|
|
log::info!("Received SIGQUIT");
|
|
Ok(())
|
|
}
|
|
Some(msg) = shutdown.wait_for_error() => {
|
|
log::info!("Task error: {:?}", msg);
|
|
Err(msg)
|
|
}
|
|
}
|
|
}
|
|
|
|
#[cfg(not(unix))]
|
|
pub async fn wait_for_signal_and_error(shutdown: &mut TaskManager) -> Result<(), SentError> {
|
|
tokio::select! {
|
|
_ = tokio::signal::ctrl_c() => {
|
|
log::info!("Received SIGINT");
|
|
Ok(())
|
|
},
|
|
Some(msg) = shutdown.wait_for_error() => {
|
|
log::info!("Task error: {:?}", msg);
|
|
Err(msg)
|
|
}
|
|
}
|
|
}
|