License (AGPL-3.0) and graceful shutdown
All checks were successful
CI / check (push) Successful in 3m48s

Add the AGPL-3.0 license (matching Orbit) and set it in Cargo.toml so
the crate metadata is complete. Handle SIGTERM/Ctrl-C: the run loop now
selects against a shutdown signal and exits cleanly, so systemctl stop
returns promptly instead of waiting out the kill timeout (every event is
already fsync'd, so nothing is lost either way). Verified: on SIGTERM the
daemon logs and exits 0.
This commit is contained in:
Jean Chevronnet 2026-07-15 12:05:39 +00:00
parent e551a01cbf
commit 9ed40a2e7f
No known key found for this signature in database
3 changed files with 697 additions and 2 deletions

View file

@ -201,5 +201,38 @@ async fn main() -> Result<()> {
let addr = format!("{}:{}", cfg.uplink.host, cfg.uplink.port);
tracing::info!(server = %cfg.server.name, %addr, "linking to uplink");
link::run(proto, engine, &addr, irc_rx, cfg.email.clone()).await
// 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.
tokio::select! {
res = link::run(proto, engine, &addr, irc_rx, cfg.email.clone()) => res,
_ = shutdown_signal() => {
tracing::info!("received shutdown signal, exiting");
Ok(())
}
}
}
// Resolve on Ctrl-C or SIGTERM (systemd stop).
async fn shutdown_signal() {
let ctrl_c = tokio::signal::ctrl_c();
#[cfg(unix)]
{
use tokio::signal::unix::{signal, SignalKind};
let mut term = match signal(SignalKind::terminate()) {
Ok(s) => s,
Err(_) => {
let _ = ctrl_c.await;
return;
}
};
tokio::select! {
_ = ctrl_c => {}
_ = term.recv() => {}
}
}
#[cfg(not(unix))]
{
let _ = ctrl_c.await;
}
}