botserv: op assigned bots on join; statserv: persist counters across restart
Some checks failed
CI / check (push) Failing after 3m48s

Problem 1: an assigned bot joined via IJOIN with no status mode, so it had no
+o. Join it with the 4-param IJOIN form (ts 1, mode o) so it's opped, matching
Anope's default bot modes (+o), and exempt bots from SECUREOPS/RESTRICTED so the
op is never stripped.

Problem 2: the shared stat counters lived only in memory, so a restart wiped
them. Snapshot them to the log (StatsSet event, folded into NetData + compaction)
periodically and on shutdown, and reseed the live registry from the log at
startup. Live gauges (online counts) stay re-derived, not stored.
This commit is contained in:
Jean Chevronnet 2026-07-16 17:32:20 +00:00
parent fd455922a5
commit 8a9b6a37ca
No known key found for this signature in database
10 changed files with 85 additions and 10 deletions

View file

@ -208,8 +208,9 @@ async fn main() -> Result<()> {
let engine = engine.clone();
tokio::spawn(async move {
loop {
tokio::time::sleep(std::time::Duration::from_secs(1800)).await;
tokio::time::sleep(std::time::Duration::from_secs(300)).await;
let mut e = engine.lock().await;
e.persist_stats(); // snapshot counters so a crash loses at most ~5 min
e.expire_sweep();
if let Err(err) = e.maybe_compact() {
tracing::warn!(%err, "compaction failed");
@ -246,9 +247,12 @@ async fn main() -> Result<()> {
// Run until the uplink loop ends or the process is asked to stop. Every
// committed change is already fsync'd, so a clean stop loses nothing; this
// just lets systemd stop us without waiting out the kill timeout.
let shutdown_engine = engine.clone();
tokio::select! {
res = link::run(proto, engine, &addr, irc_rx, cfg.email.clone()) => res,
_ = shutdown_signal() => {
// Flush stat counters so a clean stop/restart keeps StatServ history.
shutdown_engine.lock().await.persist_stats();
tracing::info!("received shutdown signal, exiting");
Ok(())
}