From 897237755f189104d260fa45f9bb42ff50c6f422 Mon Sep 17 00:00:00 2001 From: awfufu Date: Tue, 27 Jan 2026 13:52:38 +0800 Subject: [PATCH] feat: refine signal handling and add config check to systemd reload --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 14 ++++++-------- traudit.service | 1 + 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e09c68a..89a7db1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3887,7 +3887,7 @@ dependencies = [ [[package]] name = "traudit" -version = "0.0.6" +version = "0.0.7" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 41abfc9..02c3448 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "traudit" -version = "0.0.6" +version = "0.0.7" edition = "2021" authors = ["awfufu"] description = "A reverse proxy that streams audit records directly to databases." diff --git a/src/main.rs b/src/main.rs index 6656b83..48f6600 100644 --- a/src/main.rs +++ b/src/main.rs @@ -136,20 +136,18 @@ async fn main() -> anyhow::Result<()> { Err(e) => error!("failed to spawn new process: {}", e), } // Initiate graceful shutdown for this process - info!("shutting down old process gracefully..."); + info!("shutting down old process gracefully (draining connections)..."); + let _ = shutdown_tx.send(()); + // Wait for server to finish (graceful drain) + let _ = server_handle.await; } _ = sigint.recv() => { - info!("received SIGINT, shutdown..."); + info!("received SIGINT, exiting immediately..."); } _ = sigterm.recv() => { - info!("received SIGTERM, shutdown..."); + info!("received SIGTERM, exiting immediately..."); } } - // Send shutdown signal to server components - let _ = shutdown_tx.send(()); - - // Wait for server to finish (graceful drain) - let _ = server_handle.await; Ok(()) } diff --git a/traudit.service b/traudit.service index 2337aa5..665ac19 100644 --- a/traudit.service +++ b/traudit.service @@ -7,6 +7,7 @@ Type=notify RuntimeDirectory=traudit WorkingDirectory=/run/traudit ExecStart=/usr/bin/traudit -f /etc/traudit/config.yaml +ExecReload=/usr/bin/traudit -f /etc/traudit/config.yaml -t ExecReload=/bin/kill -HUP $MAINPID KillSignal=SIGINT Restart=on-failure