Fix all remaining commands to use full paths
- Fix systemctl, du, df, uptime, ss, journalctl commands - Add sudo for du command (needed for directory access) - This should resolve all remaining command path issues in the service - Storage, backup, and system monitoring should now work properly
This commit is contained in:
parent
2e67f17d6c
commit
617da088b1
@ -138,7 +138,7 @@ impl BackupCollector {
|
|||||||
// Get systemctl status for backup service
|
// Get systemctl status for backup service
|
||||||
let status_output = timeout(
|
let status_output = timeout(
|
||||||
timeout_duration,
|
timeout_duration,
|
||||||
Command::new("systemctl")
|
Command::new("/run/current-system/sw/bin/systemctl")
|
||||||
.args([
|
.args([
|
||||||
"show",
|
"show",
|
||||||
&self.backup_service,
|
&self.backup_service,
|
||||||
@ -179,7 +179,7 @@ impl BackupCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_last_backup_log_message(&self) -> Result<String, CollectorError> {
|
async fn get_last_backup_log_message(&self) -> Result<String, CollectorError> {
|
||||||
let output = Command::new("journalctl")
|
let output = Command::new("/run/current-system/sw/bin/journalctl")
|
||||||
.args([
|
.args([
|
||||||
"-u",
|
"-u",
|
||||||
&self.backup_service,
|
&self.backup_service,
|
||||||
@ -210,7 +210,7 @@ impl BackupCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_backup_logs_for_failures(&self) -> Result<Option<DateTime<Utc>>, CollectorError> {
|
async fn get_backup_logs_for_failures(&self) -> Result<Option<DateTime<Utc>>, CollectorError> {
|
||||||
let output = Command::new("journalctl")
|
let output = Command::new("/run/current-system/sw/bin/journalctl")
|
||||||
.args([
|
.args([
|
||||||
"-u",
|
"-u",
|
||||||
&self.backup_service,
|
&self.backup_service,
|
||||||
|
|||||||
@ -43,7 +43,7 @@ impl ServiceCollector {
|
|||||||
// Use more efficient systemctl command - just get the essential info
|
// Use more efficient systemctl command - just get the essential info
|
||||||
let status_output = timeout(
|
let status_output = timeout(
|
||||||
timeout_duration,
|
timeout_duration,
|
||||||
Command::new("systemctl")
|
Command::new("/run/current-system/sw/bin/systemctl")
|
||||||
.args(["show", service, "--property=ActiveState,SubState,MainPID", "--no-pager"])
|
.args(["show", service, "--property=ActiveState,SubState,MainPID", "--no-pager"])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
@ -229,8 +229,8 @@ impl ServiceCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_directory_size(&self, path: &str) -> Result<f32, CollectorError> {
|
async fn get_directory_size(&self, path: &str) -> Result<f32, CollectorError> {
|
||||||
let output = Command::new("du")
|
let output = Command::new("sudo")
|
||||||
.args(["-s", "-k", path]) // Use kilobytes instead of forcing GB
|
.args(["/run/current-system/sw/bin/du", "-s", "-k", path]) // Use kilobytes instead of forcing GB
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.output()
|
.output()
|
||||||
@ -258,7 +258,7 @@ impl ServiceCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_service_memory_limit(&self, service: &str) -> Result<f32, CollectorError> {
|
async fn get_service_memory_limit(&self, service: &str) -> Result<f32, CollectorError> {
|
||||||
let output = Command::new("systemctl")
|
let output = Command::new("/run/current-system/sw/bin/systemctl")
|
||||||
.args(["show", service, "--property=MemoryMax", "--no-pager"])
|
.args(["show", service, "--property=MemoryMax", "--no-pager"])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
@ -286,7 +286,7 @@ impl ServiceCollector {
|
|||||||
|
|
||||||
|
|
||||||
async fn get_disk_usage(&self) -> Result<DiskUsage, CollectorError> {
|
async fn get_disk_usage(&self) -> Result<DiskUsage, CollectorError> {
|
||||||
let output = Command::new("df")
|
let output = Command::new("/run/current-system/sw/bin/df")
|
||||||
.args(["-BG", "--output=size,used,avail", "/"])
|
.args(["-BG", "--output=size,used,avail", "/"])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
@ -479,7 +479,7 @@ impl ServiceCollector {
|
|||||||
|
|
||||||
async fn get_web_server_connections(&self) -> Option<String> {
|
async fn get_web_server_connections(&self) -> Option<String> {
|
||||||
// Use simpler ss command with minimal output
|
// Use simpler ss command with minimal output
|
||||||
let output = Command::new("ss")
|
let output = Command::new("/run/current-system/sw/bin/ss")
|
||||||
.args(["-tn", "state", "established", "sport", ":80", "or", "sport", ":443"])
|
.args(["-tn", "state", "established", "sport", ":80", "or", "sport", ":443"])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
@ -645,7 +645,7 @@ impl ServiceCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_nginx_config_from_systemd(&self) -> Option<String> {
|
async fn get_nginx_config_from_systemd(&self) -> Option<String> {
|
||||||
let output = Command::new("systemctl")
|
let output = Command::new("/run/current-system/sw/bin/systemctl")
|
||||||
.args(["show", "nginx", "--property=ExecStart", "--no-pager"])
|
.args(["show", "nginx", "--property=ExecStart", "--no-pager"])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
|
|||||||
@ -48,8 +48,8 @@ impl SmartCollector {
|
|||||||
|
|
||||||
let command_result = timeout(
|
let command_result = timeout(
|
||||||
timeout_duration,
|
timeout_duration,
|
||||||
Command::new("smartctl")
|
Command::new("sudo")
|
||||||
.args(["-a", "-j", &format!("/dev/{}", device)])
|
.args(["/run/current-system/sw/bin/smartctl", "-a", "-j", &format!("/dev/{}", device)])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.output(),
|
.output(),
|
||||||
@ -132,7 +132,7 @@ impl SmartCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_drive_capacity(&self, device: &str) -> Result<f32, CollectorError> {
|
async fn get_drive_capacity(&self, device: &str) -> Result<f32, CollectorError> {
|
||||||
let output = Command::new("lsblk")
|
let output = Command::new("/run/current-system/sw/bin/lsblk")
|
||||||
.args(["-J", "-o", "NAME,SIZE", &format!("/dev/{}", device)])
|
.args(["-J", "-o", "NAME,SIZE", &format!("/dev/{}", device)])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
@ -204,7 +204,7 @@ impl SmartCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_disk_usage(&self) -> Result<DiskUsage, CollectorError> {
|
async fn get_disk_usage(&self) -> Result<DiskUsage, CollectorError> {
|
||||||
let output = Command::new("df")
|
let output = Command::new("/run/current-system/sw/bin/df")
|
||||||
.args(["-BG", "--output=size,used,avail", "/"])
|
.args(["-BG", "--output=size,used,avail", "/"])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
|
|||||||
@ -21,7 +21,7 @@ impl SystemCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_cpu_load(&self) -> Result<(f32, f32, f32), CollectorError> {
|
async fn get_cpu_load(&self) -> Result<(f32, f32, f32), CollectorError> {
|
||||||
let output = Command::new("uptime")
|
let output = Command::new("/run/current-system/sw/bin/uptime")
|
||||||
.output()
|
.output()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| CollectorError::CommandFailed {
|
.map_err(|e| CollectorError::CommandFailed {
|
||||||
|
|||||||
@ -43,7 +43,7 @@ impl AutoDiscovery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn discover_via_lsblk() -> Result<Vec<String>, CollectorError> {
|
async fn discover_via_lsblk() -> Result<Vec<String>, CollectorError> {
|
||||||
let output = Command::new("lsblk")
|
let output = Command::new("/run/current-system/sw/bin/lsblk")
|
||||||
.args(["-d", "-o", "NAME,TYPE", "-n", "-r"])
|
.args(["-d", "-o", "NAME,TYPE", "-n", "-r"])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
@ -155,7 +155,7 @@ impl AutoDiscovery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn discover_running_services() -> Result<Vec<String>, CollectorError> {
|
async fn discover_running_services() -> Result<Vec<String>, CollectorError> {
|
||||||
let output = Command::new("systemctl")
|
let output = Command::new("/run/current-system/sw/bin/systemctl")
|
||||||
.args([
|
.args([
|
||||||
"list-units",
|
"list-units",
|
||||||
"--type=service",
|
"--type=service",
|
||||||
@ -280,7 +280,7 @@ impl AutoDiscovery {
|
|||||||
format!("{}.service", service)
|
format!("{}.service", service)
|
||||||
};
|
};
|
||||||
|
|
||||||
match Command::new("systemctl")
|
match Command::new("/run/current-system/sw/bin/systemctl")
|
||||||
.args(["status", &unit])
|
.args(["status", &unit])
|
||||||
.stdout(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
.stderr(Stdio::null())
|
.stderr(Stdio::null())
|
||||||
@ -320,7 +320,7 @@ impl AutoDiscovery {
|
|||||||
let backup_services = ["restic", "borg", "duplicati", "rclone"];
|
let backup_services = ["restic", "borg", "duplicati", "rclone"];
|
||||||
|
|
||||||
for service in backup_services {
|
for service in backup_services {
|
||||||
if let Ok(output) = Command::new("systemctl")
|
if let Ok(output) = Command::new("/run/current-system/sw/bin/systemctl")
|
||||||
.args(["is-enabled", service])
|
.args(["is-enabled", service])
|
||||||
.output()
|
.output()
|
||||||
.await
|
.await
|
||||||
@ -366,7 +366,7 @@ impl AutoDiscovery {
|
|||||||
let backup_services = ["restic-backup", "restic", "borg-backup", "borg", "backup"];
|
let backup_services = ["restic-backup", "restic", "borg-backup", "borg", "backup"];
|
||||||
|
|
||||||
for service in backup_services {
|
for service in backup_services {
|
||||||
if let Ok(output) = Command::new("systemctl")
|
if let Ok(output) = Command::new("/run/current-system/sw/bin/systemctl")
|
||||||
.args(["is-enabled", &format!("{}.service", service)])
|
.args(["is-enabled", &format!("{}.service", service)])
|
||||||
.output()
|
.output()
|
||||||
.await
|
.await
|
||||||
@ -399,8 +399,8 @@ impl AutoDiscovery {
|
|||||||
let device_path = format!("/dev/{}", device);
|
let device_path = format!("/dev/{}", device);
|
||||||
|
|
||||||
// Try to run smartctl to see if device is accessible
|
// Try to run smartctl to see if device is accessible
|
||||||
if let Ok(output) = Command::new("smartctl")
|
if let Ok(output) = Command::new("sudo")
|
||||||
.args(["-i", &device_path])
|
.args(["/run/current-system/sw/bin/smartctl", "-i", &device_path])
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.output()
|
.output()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user