From 617da088b107b8c25197ea5da3d694cd7b4929ea Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Mon, 13 Oct 2025 17:44:13 +0200 Subject: [PATCH] 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 --- agent/src/collectors/backup.rs | 6 +++--- agent/src/collectors/service.rs | 14 +++++++------- agent/src/collectors/smart.rs | 8 ++++---- agent/src/collectors/system.rs | 2 +- agent/src/discovery.rs | 14 +++++++------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/agent/src/collectors/backup.rs b/agent/src/collectors/backup.rs index fb6aa55..5f03ebb 100644 --- a/agent/src/collectors/backup.rs +++ b/agent/src/collectors/backup.rs @@ -138,7 +138,7 @@ impl BackupCollector { // Get systemctl status for backup service let status_output = timeout( timeout_duration, - Command::new("systemctl") + Command::new("/run/current-system/sw/bin/systemctl") .args([ "show", &self.backup_service, @@ -179,7 +179,7 @@ impl BackupCollector { } async fn get_last_backup_log_message(&self) -> Result { - let output = Command::new("journalctl") + let output = Command::new("/run/current-system/sw/bin/journalctl") .args([ "-u", &self.backup_service, @@ -210,7 +210,7 @@ impl BackupCollector { } async fn get_backup_logs_for_failures(&self) -> Result>, CollectorError> { - let output = Command::new("journalctl") + let output = Command::new("/run/current-system/sw/bin/journalctl") .args([ "-u", &self.backup_service, diff --git a/agent/src/collectors/service.rs b/agent/src/collectors/service.rs index f80902c..655a220 100644 --- a/agent/src/collectors/service.rs +++ b/agent/src/collectors/service.rs @@ -43,7 +43,7 @@ impl ServiceCollector { // Use more efficient systemctl command - just get the essential info let status_output = timeout( timeout_duration, - Command::new("systemctl") + Command::new("/run/current-system/sw/bin/systemctl") .args(["show", service, "--property=ActiveState,SubState,MainPID", "--no-pager"]) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -229,8 +229,8 @@ impl ServiceCollector { } async fn get_directory_size(&self, path: &str) -> Result { - let output = Command::new("du") - .args(["-s", "-k", path]) // Use kilobytes instead of forcing GB + let output = Command::new("sudo") + .args(["/run/current-system/sw/bin/du", "-s", "-k", path]) // Use kilobytes instead of forcing GB .stdout(Stdio::piped()) .stderr(Stdio::piped()) .output() @@ -258,7 +258,7 @@ impl ServiceCollector { } async fn get_service_memory_limit(&self, service: &str) -> Result { - let output = Command::new("systemctl") + let output = Command::new("/run/current-system/sw/bin/systemctl") .args(["show", service, "--property=MemoryMax", "--no-pager"]) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -286,7 +286,7 @@ impl ServiceCollector { async fn get_disk_usage(&self) -> Result { - let output = Command::new("df") + let output = Command::new("/run/current-system/sw/bin/df") .args(["-BG", "--output=size,used,avail", "/"]) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -479,7 +479,7 @@ impl ServiceCollector { async fn get_web_server_connections(&self) -> Option { // 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"]) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -645,7 +645,7 @@ impl ServiceCollector { } async fn get_nginx_config_from_systemd(&self) -> Option { - let output = Command::new("systemctl") + let output = Command::new("/run/current-system/sw/bin/systemctl") .args(["show", "nginx", "--property=ExecStart", "--no-pager"]) .stdout(Stdio::piped()) .stderr(Stdio::piped()) diff --git a/agent/src/collectors/smart.rs b/agent/src/collectors/smart.rs index 5476336..bad462c 100644 --- a/agent/src/collectors/smart.rs +++ b/agent/src/collectors/smart.rs @@ -48,8 +48,8 @@ impl SmartCollector { let command_result = timeout( timeout_duration, - Command::new("smartctl") - .args(["-a", "-j", &format!("/dev/{}", device)]) + Command::new("sudo") + .args(["/run/current-system/sw/bin/smartctl", "-a", "-j", &format!("/dev/{}", device)]) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .output(), @@ -132,7 +132,7 @@ impl SmartCollector { } async fn get_drive_capacity(&self, device: &str) -> Result { - let output = Command::new("lsblk") + let output = Command::new("/run/current-system/sw/bin/lsblk") .args(["-J", "-o", "NAME,SIZE", &format!("/dev/{}", device)]) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -204,7 +204,7 @@ impl SmartCollector { } async fn get_disk_usage(&self) -> Result { - let output = Command::new("df") + let output = Command::new("/run/current-system/sw/bin/df") .args(["-BG", "--output=size,used,avail", "/"]) .stdout(Stdio::piped()) .stderr(Stdio::piped()) diff --git a/agent/src/collectors/system.rs b/agent/src/collectors/system.rs index 4b7a85d..dc74aa0 100644 --- a/agent/src/collectors/system.rs +++ b/agent/src/collectors/system.rs @@ -21,7 +21,7 @@ impl SystemCollector { } 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() .await .map_err(|e| CollectorError::CommandFailed { diff --git a/agent/src/discovery.rs b/agent/src/discovery.rs index 2c87968..0a6746f 100644 --- a/agent/src/discovery.rs +++ b/agent/src/discovery.rs @@ -43,7 +43,7 @@ impl AutoDiscovery { } async fn discover_via_lsblk() -> Result, CollectorError> { - let output = Command::new("lsblk") + let output = Command::new("/run/current-system/sw/bin/lsblk") .args(["-d", "-o", "NAME,TYPE", "-n", "-r"]) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -155,7 +155,7 @@ impl AutoDiscovery { } async fn discover_running_services() -> Result, CollectorError> { - let output = Command::new("systemctl") + let output = Command::new("/run/current-system/sw/bin/systemctl") .args([ "list-units", "--type=service", @@ -280,7 +280,7 @@ impl AutoDiscovery { format!("{}.service", service) }; - match Command::new("systemctl") + match Command::new("/run/current-system/sw/bin/systemctl") .args(["status", &unit]) .stdout(Stdio::null()) .stderr(Stdio::null()) @@ -320,7 +320,7 @@ impl AutoDiscovery { let backup_services = ["restic", "borg", "duplicati", "rclone"]; 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]) .output() .await @@ -366,7 +366,7 @@ impl AutoDiscovery { let backup_services = ["restic-backup", "restic", "borg-backup", "borg", "backup"]; 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)]) .output() .await @@ -399,8 +399,8 @@ impl AutoDiscovery { let device_path = format!("/dev/{}", device); // Try to run smartctl to see if device is accessible - if let Ok(output) = Command::new("smartctl") - .args(["-i", &device_path]) + if let Ok(output) = Command::new("sudo") + .args(["/run/current-system/sw/bin/smartctl", "-i", &device_path]) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .output()