From f786d054f2ece80823f85e46933857af96e241b2 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Mon, 13 Oct 2025 12:12:36 +0200 Subject: [PATCH] Fix nginx config parsing for NixOS systemd format Improve parsing of nginx config path from systemd ExecStart to handle both traditional format and NixOS argv[] format. This should fix nginx sites not being detected when running as a systemd service. --- agent/src/collectors/service.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/agent/src/collectors/service.rs b/agent/src/collectors/service.rs index 0b9210c..a2f5007 100644 --- a/agent/src/collectors/service.rs +++ b/agent/src/collectors/service.rs @@ -640,16 +640,19 @@ impl ServiceCollector { // Parse ExecStart to extract -c config path for line in stdout.lines() { if line.starts_with("ExecStart=") { - // Look for "-c /path/to/config" in the command line + // Handle both traditional and NixOS systemd formats + // Traditional: ExecStart=/path/nginx -c /config + // NixOS: ExecStart={ path=...; argv[]=...nginx -c /config; ... } + if let Some(c_index) = line.find(" -c ") { let after_c = &line[c_index + 4..]; - if let Some(space_index) = after_c.find(' ') { - return Some(after_c[..space_index].to_string()); - } else { - // -c is the last argument, clean up systemd formatting - let cleaned = after_c.trim_end_matches(" ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }"); - return Some(cleaned.to_string()); - } + // Find the end of the config path + let end_pos = after_c.find(' ') + .or_else(|| after_c.find(" ;")) // NixOS format ends with " ;" + .unwrap_or(after_c.len()); + + let config_path = after_c[..end_pos].trim(); + return Some(config_path.to_string()); } } }