Fix nginx detection when running as root - skip sudo
This commit is contained in:
parent
9b6a504e48
commit
92d6b42837
@ -572,6 +572,11 @@ impl ServiceCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_running_as_root(&self) -> bool {
|
||||||
|
std::env::var("USER").unwrap_or_default() == "root" ||
|
||||||
|
std::env::var("UID").unwrap_or_default() == "0"
|
||||||
|
}
|
||||||
|
|
||||||
async fn get_nginx_sites(&self) -> Option<Vec<String>> {
|
async fn get_nginx_sites(&self) -> Option<Vec<String>> {
|
||||||
|
|
||||||
// Get the actual nginx config file path from systemd (NixOS uses custom config)
|
// Get the actual nginx config file path from systemd (NixOS uses custom config)
|
||||||
@ -579,8 +584,16 @@ impl ServiceCollector {
|
|||||||
Some(path) => path,
|
Some(path) => path,
|
||||||
None => {
|
None => {
|
||||||
// Fallback to default nginx -T
|
// Fallback to default nginx -T
|
||||||
match Command::new("sudo")
|
let mut cmd = if self.is_running_as_root() {
|
||||||
.args(["nginx", "-T"])
|
Command::new("nginx")
|
||||||
|
} else {
|
||||||
|
let mut cmd = Command::new("sudo");
|
||||||
|
cmd.arg("nginx");
|
||||||
|
cmd
|
||||||
|
};
|
||||||
|
|
||||||
|
match cmd
|
||||||
|
.args(["-T"])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.output()
|
.output()
|
||||||
@ -601,8 +614,16 @@ impl ServiceCollector {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Use the specific config file
|
// Use the specific config file
|
||||||
let output = match Command::new("sudo")
|
let mut cmd = if self.is_running_as_root() {
|
||||||
.args(["nginx", "-T", "-c", &config_path])
|
Command::new("nginx")
|
||||||
|
} else {
|
||||||
|
let mut cmd = Command::new("sudo");
|
||||||
|
cmd.arg("nginx");
|
||||||
|
cmd
|
||||||
|
};
|
||||||
|
|
||||||
|
let output = match cmd
|
||||||
|
.args(["-T", "-c", &config_path])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.output()
|
.output()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user