initial commit
This commit is contained in:
commit
2a9f427bc7
21 changed files with 3692 additions and 0 deletions
32
src/signals.rs
Normal file
32
src/signals.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
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...");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue