Gracefully shutdown if LDAP connection is lost
This commit is contained in:
parent
7851d6bb12
commit
c7b0cfc888
|
@ -3,7 +3,7 @@ use russh::keys::PublicKey;
|
||||||
use tokio::select;
|
use tokio::select;
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
use tracing::{debug, warn};
|
use tracing::{debug, error};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Ldap {
|
pub struct Ldap {
|
||||||
|
@ -51,9 +51,10 @@ impl Ldap {
|
||||||
select! {
|
select! {
|
||||||
res = conn.drive() => {
|
res = conn.drive() => {
|
||||||
if let Err(err) = res {
|
if let Err(err) = res {
|
||||||
warn!("LDAP connection error: {}", err);
|
error!("LDAP connection error: {}", err);
|
||||||
} else {
|
} else {
|
||||||
debug!("LDAP drive has stopped, this should not happen?");
|
error!("LDAP connection lost");
|
||||||
|
token.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = token.cancelled() => {
|
_ = token.cancelled() => {
|
||||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -15,15 +15,20 @@ use siranga::web::{ForwardAuth, Service};
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use tokio::select;
|
use tokio::select;
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
use tracing::{error, info, warn};
|
use tracing::{debug, error, info, warn};
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
use tracing_subscriber::layer::SubscriberExt;
|
use tracing_subscriber::layer::SubscriberExt;
|
||||||
use tracing_subscriber::util::SubscriberInitExt;
|
use tracing_subscriber::util::SubscriberInitExt;
|
||||||
|
|
||||||
async fn shutdown_task(token: CancellationToken) {
|
async fn shutdown_task(token: CancellationToken) {
|
||||||
tokio::signal::ctrl_c()
|
select! {
|
||||||
.await
|
_ = tokio::signal::ctrl_c() => {
|
||||||
.expect("Failed to listen for ctrl-c event");
|
debug!("Received SIGINT");
|
||||||
|
}
|
||||||
|
_ = token.cancelled() => {
|
||||||
|
debug!("Application called for graceful shutdown");
|
||||||
|
}
|
||||||
|
}
|
||||||
info!("Starting graceful shutdown");
|
info!("Starting graceful shutdown");
|
||||||
token.cancel();
|
token.cancel();
|
||||||
tokio::time::sleep(Duration::from_secs(5)).await;
|
tokio::time::sleep(Duration::from_secs(5)).await;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user