B: B4 start the peer registry from serve and reload peers on SIGHUP
This commit is contained in:
1 parent
d94c2b3a1d
commit
ed1c3a608e
2 files changed
+57
-27
No files matched your search
+24
-7
@@ -22,6 +22,7 @@ use tokio_rustls::TlsAcceptor;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
use crate::config::TlsConfig;
|
||||
use crate::peers::registry::PeersReloader;
|
||||
|
||||
/// Hot-swappable server certificate.
|
||||
#[derive(Debug)]
|
||||
@@ -101,10 +102,14 @@ pub fn acceptor(cert: Arc<ReloadableCert>) -> Result<TlsAcceptor> {
|
||||
/// Reload on every SIGHUP until `shutdown`. Failures are logged, never fatal.
|
||||
/// `hup` is installed by the caller before binding so no SIGHUP can kill the
|
||||
/// process in the meantime.
|
||||
///
|
||||
/// `cert` is `None` when TLS is disabled; `peers` is `None` when the peers
|
||||
/// feature is off. The same signal reloads both, with independent failures.
|
||||
pub fn spawn_sighup_reload(
|
||||
cert: Arc<ReloadableCert>,
|
||||
cert: Option<Arc<ReloadableCert>>,
|
||||
mut hup: tokio::signal::unix::Signal,
|
||||
shutdown: CancellationToken,
|
||||
peers: Option<PeersReloader>,
|
||||
) {
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
@@ -112,12 +117,24 @@ pub fn spawn_sighup_reload(
|
||||
_ = shutdown.cancelled() => break,
|
||||
r = hup.recv() => if r.is_none() { break },
|
||||
}
|
||||
match cert.reload() {
|
||||
Ok(()) => tracing::info!("TLS certificate reloaded"),
|
||||
Err(e) => tracing::error!(
|
||||
error = %format!("{e:#}"),
|
||||
"TLS reload failed; keeping previous certificate"
|
||||
),
|
||||
match &cert {
|
||||
Some(cert) => match cert.reload() {
|
||||
Ok(()) => tracing::info!("TLS certificate reloaded"),
|
||||
Err(e) => tracing::error!(
|
||||
error = %format!("{e:#}"),
|
||||
"TLS reload failed; keeping previous certificate"
|
||||
),
|
||||
},
|
||||
None => tracing::info!("SIGHUP received; TLS is disabled"),
|
||||
}
|
||||
if let Some(peers) = &peers {
|
||||
match peers.reload().await {
|
||||
Ok(()) => tracing::info!("peer configuration reloaded"),
|
||||
Err(e) => tracing::error!(
|
||||
error = %e,
|
||||
"peer reload failed; keeping previous peers"
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user