Testing
This commit is contained in:
parent
b287eb35fd
commit
e9d42568fb
@ -637,17 +637,50 @@ impl ServiceCollector {
|
|||||||
async fn get_nginx_sites(&self) -> Option<Vec<String>> {
|
async fn get_nginx_sites(&self) -> Option<Vec<String>> {
|
||||||
tracing::debug!("Starting nginx site detection");
|
tracing::debug!("Starting nginx site detection");
|
||||||
|
|
||||||
// For NixOS and other systems, get the actual running nginx config
|
// Get the actual nginx config file path from systemd (NixOS uses custom config)
|
||||||
let output = match Command::new("sudo")
|
let config_path = match self.get_nginx_config_from_systemd().await {
|
||||||
|
Some(path) => {
|
||||||
|
tracing::debug!("Found nginx config path from systemd: {}", path);
|
||||||
|
path
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
tracing::warn!("Could not find nginx config path from systemd, using default");
|
||||||
|
// Fallback to default nginx -T
|
||||||
|
match Command::new("sudo")
|
||||||
.args(["nginx", "-T"])
|
.args(["nginx", "-T"])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.output()
|
.output()
|
||||||
.await
|
.await
|
||||||
|
{
|
||||||
|
Ok(output) => {
|
||||||
|
if !output.status.success() {
|
||||||
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||||
|
tracing::warn!("nginx -T failed with status {}: {}", output.status, stderr);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let config = String::from_utf8_lossy(&output.stdout);
|
||||||
|
return self.parse_nginx_config(&config);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
tracing::warn!("Failed to execute sudo nginx -T: {}", e);
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use the specific config file
|
||||||
|
let output = match Command::new("sudo")
|
||||||
|
.args(["nginx", "-T", "-c", &config_path])
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.stderr(Stdio::piped())
|
||||||
|
.output()
|
||||||
|
.await
|
||||||
{
|
{
|
||||||
Ok(output) => output,
|
Ok(output) => output,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::warn!("Failed to execute sudo nginx -T: {}", e);
|
tracing::warn!("Failed to execute sudo nginx -T -c {}: {}", config_path, e);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -661,6 +694,43 @@ impl ServiceCollector {
|
|||||||
let config = String::from_utf8_lossy(&output.stdout);
|
let config = String::from_utf8_lossy(&output.stdout);
|
||||||
tracing::debug!("Got nginx config, {} bytes", config.len());
|
tracing::debug!("Got nginx config, {} bytes", config.len());
|
||||||
|
|
||||||
|
self.parse_nginx_config(&config)
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_nginx_config_from_systemd(&self) -> Option<String> {
|
||||||
|
let output = Command::new("systemctl")
|
||||||
|
.args(["show", "nginx", "--property=ExecStart", "--no-pager"])
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.stderr(Stdio::piped())
|
||||||
|
.output()
|
||||||
|
.await
|
||||||
|
.ok()?;
|
||||||
|
|
||||||
|
if !output.status.success() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||||
|
// 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
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse_nginx_config(&self, config: &str) -> Option<Vec<String>> {
|
||||||
let mut sites = Vec::new();
|
let mut sites = Vec::new();
|
||||||
let mut server_name_lines = 0;
|
let mut server_name_lines = 0;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user