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:
Christoffer Martinsson 2025-10-13 17:44:13 +02:00
parent 2e67f17d6c
commit 617da088b1
5 changed files with 22 additions and 22 deletions

View File

@ -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<String, CollectorError> {
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<Option<DateTime<Utc>>, CollectorError> {
let output = Command::new("journalctl")
let output = Command::new("/run/current-system/sw/bin/journalctl")
.args([
"-u",
&self.backup_service,

View File

@ -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<f32, CollectorError> {
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<f32, CollectorError> {
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<DiskUsage, CollectorError> {
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<String> {
// 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<String> {
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())

View File

@ -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<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)])
.stdout(Stdio::piped())
.stderr(Stdio::piped())
@ -204,7 +204,7 @@ impl SmartCollector {
}
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", "/"])
.stdout(Stdio::piped())
.stderr(Stdio::piped())

View File

@ -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 {

View File

@ -43,7 +43,7 @@ impl AutoDiscovery {
}
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"])
.stdout(Stdio::piped())
.stderr(Stdio::piped())
@ -155,7 +155,7 @@ impl AutoDiscovery {
}
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([
"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()