Added a singal handler to make USR1 reload the geoip databses

This commit is contained in:
Slatian 2023-03-26 16:07:28 +02:00
parent 6a57780490
commit a9512d7d4d

View File

@ -27,6 +27,12 @@ use trust_dns_resolver::{
// config::ResolverConfig, // config::ResolverConfig,
}; };
use tokio::signal::unix::{
signal,
SignalKind,
};
use tokio::task;
use std::fs; use std::fs;
use std::net::IpAddr; use std::net::IpAddr;
use std::sync::Arc; use std::sync::Arc;
@ -245,6 +251,26 @@ async fn main() {
config: config.clone(), config: config.clone(),
}); });
let signal_usr1_handlers_state = shared_state.clone();
task::spawn(async move {
println!("Trying to register USR1 signal for reloading geoip databases");
let mut signal_stream = match signal(SignalKind::user_defined1()) {
Ok(signal_stream) => signal_stream,
Err(e) => {
println!("Error while registring signal handler: {e}");
println!("Continuing without ...");
return;
}
};
loop {
if None == signal_stream.recv().await { return; }
println!("Received signal USR1, reloading geoip databses!");
signal_usr1_handlers_state.location_db.reload_database().ok();
signal_usr1_handlers_state.asn_db.reload_database().ok();
}
});
// Initalize axum server // Initalize axum server
let app = Router::new() let app = Router::new()
.route("/", get(handle_default_route)) .route("/", get(handle_default_route))