33 lines
915 B
Rust
33 lines
915 B
Rust
use tokio::signal;
|
|
use tracing::debug;
|
|
|
|
///
|
|
/// Handle SIGTERM and SIGINT on our own. This is needed for the process to behave properly when
|
|
/// running as PID 1 (as is the case as the sole thing in a container).
|
|
///
|
|
/// Includes configuration for non-unix systems but that is untested as well as not expected to be
|
|
/// used.
|
|
pub(crate) async fn shutdown() {
|
|
let ctrl_c = async {
|
|
signal::ctrl_c()
|
|
.await
|
|
.expect("failed to install Ctrl+C handler");
|
|
};
|
|
|
|
#[cfg(unix)]
|
|
let terminate = async {
|
|
signal::unix::signal(signal::unix::SignalKind::terminate())
|
|
.expect("failed to install signal handler")
|
|
.recv()
|
|
.await;
|
|
};
|
|
#[cfg(not(unix))]
|
|
let terminate = std::future::pending::<()>();
|
|
|
|
tokio::select! {
|
|
_ = ctrl_c => {},
|
|
_ = terminate => {},
|
|
}
|
|
debug!("signal received, shutting down...");
|
|
}
|