From 4a6e1d817ba18683ed9b39fe9f509b4295a089be Mon Sep 17 00:00:00 2001 From: Ara Sadoyan Date: Tue, 2 Jun 2026 19:56:08 +0200 Subject: [PATCH] OS signals , PID file --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/web/start.rs | 5 ++++- src/web/webserver.rs | 15 +-------------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b10b7ec..57115be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -154,6 +154,7 @@ dependencies = [ "rcgen", "reqwest", "rustls-pemfile", + "sd-notify", "serde", "serde_json", "serde_yml", @@ -3404,6 +3405,15 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sd-notify" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e4ef7359e694bfaf1dd27a30f9d760b54c00dfae9f19bd0c05a39bc9128fe76" +dependencies = [ + "libc", +] + [[package]] name = "sec1" version = "0.7.3" diff --git a/Cargo.toml b/Cargo.toml index a427942..344eafb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,3 +50,4 @@ log4rs = "1.4.0" tikv-jemallocator = "0.7.0" tikv-jemalloc-ctl = { version = "0.7.0", features = ["stats"] } signal-hook = "0.4.4" +sd-notify = "0.5.0" diff --git a/src/web/start.rs b/src/web/start.rs index 827a8a2..e6cdb92 100644 --- a/src/web/start.rs +++ b/src/web/start.rs @@ -13,6 +13,7 @@ use pingora_core::listeners::tls::TlsSettings; use pingora_core::prelude::{background_service, Opt}; use pingora_core::server::Server; use privdrop::reexports::libc::SIGQUIT; +use sd_notify::NotifyState; use signal_hook::{ consts::{SIGINT, SIGTERM}, iterator::Signals, @@ -20,7 +21,7 @@ use signal_hook::{ use std::sync::mpsc::{channel, Receiver, Sender}; use std::sync::Arc; use std::time::Duration; -use std::{fs, thread}; +use std::{fs, process, thread}; pub fn run() { // default_provider().install_default().expect("Failed to install rustls crypto provider"); @@ -115,6 +116,8 @@ pub fn run() { if let (Some(user), Some(group)) = (cfg.rungroup.clone(), cfg.runuser.clone()) { drop_priv(user, group, cfg.proxy_address_http.clone(), cfg.proxy_address_tls.clone()); } + let _ = sd_notify::notify(&[NotifyState::Ready]); + let _ = fs::write("/tmp/aralez.pid", process::id().to_string()); let mut signals = Signals::new(&[SIGINT, SIGTERM, SIGQUIT]).unwrap(); for sig in signals.forever() { diff --git a/src/web/webserver.rs b/src/web/webserver.rs index 0aac67e..81784e0 100644 --- a/src/web/webserver.rs +++ b/src/web/webserver.rs @@ -88,25 +88,12 @@ pub async fn run_server(config: &APIUpstreamProvider, mut to_return: Sender, Query(params): Query>, content: String) -> impl IntoResponse {