mirror of
https://codeberg.org/slatian/service.echoip-slatecave.git
synced 2025-04-05 12:05:40 +02:00
Added a singal handler to make USR1 reload the geoip databses
This commit is contained in:
parent
6a57780490
commit
a9512d7d4d
26
src/main.rs
26
src/main.rs
@ -27,6 +27,12 @@ use trust_dns_resolver::{
|
||||
// config::ResolverConfig,
|
||||
};
|
||||
|
||||
use tokio::signal::unix::{
|
||||
signal,
|
||||
SignalKind,
|
||||
};
|
||||
use tokio::task;
|
||||
|
||||
use std::fs;
|
||||
use std::net::IpAddr;
|
||||
use std::sync::Arc;
|
||||
@ -245,6 +251,26 @@ async fn main() {
|
||||
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
|
||||
let app = Router::new()
|
||||
.route("/", get(handle_default_route))
|
||||
|
Loading…
x
Reference in New Issue
Block a user