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.
This commit is contained in:
parent
b0d7d5ce35
commit
f786d054f2
@ -640,16 +640,19 @@ impl ServiceCollector {
|
|||||||
// Parse ExecStart to extract -c config path
|
// Parse ExecStart to extract -c config path
|
||||||
for line in stdout.lines() {
|
for line in stdout.lines() {
|
||||||
if line.starts_with("ExecStart=") {
|
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 ") {
|
if let Some(c_index) = line.find(" -c ") {
|
||||||
let after_c = &line[c_index + 4..];
|
let after_c = &line[c_index + 4..];
|
||||||
if let Some(space_index) = after_c.find(' ') {
|
// Find the end of the config path
|
||||||
return Some(after_c[..space_index].to_string());
|
let end_pos = after_c.find(' ')
|
||||||
} else {
|
.or_else(|| after_c.find(" ;")) // NixOS format ends with " ;"
|
||||||
// -c is the last argument, clean up systemd formatting
|
.unwrap_or(after_c.len());
|
||||||
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());
|
let config_path = after_c[..end_pos].trim();
|
||||||
}
|
return Some(config_path.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user