chore(tls-reload): Improve tls reloading & remove deps on rust 1.75
This commit is contained in:
parent
f373293ede
commit
41a88beb8d
1 changed files with 9 additions and 8 deletions
|
@ -3,12 +3,11 @@ use anyhow::Context;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use notify::{EventKind, RecommendedWatcher, Watcher};
|
use notify::{EventKind, RecommendedWatcher, Watcher};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use std::fs::File;
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::Duration;
|
||||||
use tracing::{error, info, warn};
|
use tracing::{error, info, warn};
|
||||||
|
|
||||||
struct TlsReloaderState {
|
struct TlsReloaderState {
|
||||||
|
@ -83,13 +82,13 @@ impl TlsReloader {
|
||||||
};
|
};
|
||||||
drop(watcher);
|
drop(watcher);
|
||||||
|
|
||||||
let Ok(file) = File::open(&path) else {
|
// Generate a fake event to force-reload the certificate
|
||||||
return;
|
let event = notify::Event {
|
||||||
|
kind: EventKind::Create(notify::event::CreateKind::Any),
|
||||||
|
paths: vec![path],
|
||||||
|
attrs: Default::default(),
|
||||||
};
|
};
|
||||||
let _ = file.set_modified(SystemTime::now()).map_err(|err| {
|
Self::handle_fs_event(&this, Ok(event));
|
||||||
error!("Cannot force reload TLS file {:?}: {:?}", path, err);
|
|
||||||
error!("Old certificate will be used until the next change");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +115,7 @@ impl TlsReloader {
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!("Error while loading TLS certificate {:?}", err);
|
warn!("Error while loading TLS certificate {:?}", err);
|
||||||
|
Self::try_rewatch_certificate(this.clone(), path.to_path_buf());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
EventKind::Remove(_) => {
|
EventKind::Remove(_) => {
|
||||||
|
@ -137,6 +137,7 @@ impl TlsReloader {
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
warn!("Error while loading TLS private key {:?}", err);
|
warn!("Error while loading TLS private key {:?}", err);
|
||||||
|
Self::try_rewatch_certificate(this.clone(), path.to_path_buf());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
EventKind::Remove(_) => {
|
EventKind::Remove(_) => {
|
||||||
|
|
Loading…
Reference in a new issue