From 4b32db0d265f8d6ab0fc81327979b0d12d7289d4 Mon Sep 17 00:00:00 2001 From: Echo Date: Tue, 5 May 2026 16:25:59 +0000 Subject: [PATCH] fix: detect socket activation for service status healthy logic --- Cargo.toml | 2 +- debian/changelog | 8 ++++++++ src/packages/mod.rs | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8082709..7f24409 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "linux-patch-api" -version = "0.3.8" +version = "0.3.9" edition = "2021" authors = ["Echo "] description = "Secure remote package management API for Linux systems" diff --git a/debian/changelog b/debian/changelog index a8ef56e..c6ee1ab 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +linux-patch-api (0.3.9-1) unstable; urgency=low + + * Fix socket activation detection for service status healthy logic + * When service is inactive but enabled, check if .socket unit is active + * Mark service healthy if socket is listening (e.g., ssh.socket for ssh.service) + + -- Echo Mon, 05 May 2026 11:25:00 -0500 + linux-patch-api (0.3.8-1) unstable; urgency=low * Add GET /api/v1/system/services/{name} endpoint for service health checks diff --git a/src/packages/mod.rs b/src/packages/mod.rs index c96b9c8..4fcfe1f 100644 --- a/src/packages/mod.rs +++ b/src/packages/mod.rs @@ -568,6 +568,28 @@ fn get_systemd_service_status(name: &str) -> Result> { let healthy = active_state == "active" && sub_state == "running"; + + // Check for socket activation: if service is inactive but enabled, + // check if the corresponding .socket unit is active (listening) + let healthy = if !healthy && active_state == "inactive" && unit_file_state == "enabled" { + let socket_name = format!("{}.socket", name.trim_end_matches(".service")); + if let Ok(socket_output) = Command::new("systemctl") + .args(["show", &socket_name, "--property=ActiveState", "--no-pager"]) + .output() + { + let socket_stdout = String::from_utf8_lossy(&socket_output.stdout); + if socket_stdout.contains("ActiveState=active") { + true + } else { + healthy + } + } else { + healthy + } + } else { + healthy + }; + Ok(Some(ServiceStatus { name: id, display_name: description,