Phase 2: Remove user service collection logic

Remove all sudo -u systemctl commands and user service processing.
Now only collects system services via systemctl list-units/list-unit-files.
Eliminates user service discovery completely as planned in TODO.md.
This commit is contained in:
Christoffer Martinsson 2025-10-23 12:32:19 +02:00
parent 616fad2c5d
commit 9133e18090

View File

@ -132,54 +132,13 @@ impl SystemdCollector {
.arg("--plain")
.output()?;
// Use configured user mapping instead of hardcoded hostname logic
let target_user = &self.config.host_user_mapping;
// Also get user unit files (user-level services) for target user
let user_unit_files_output = Command::new("sudo")
.arg("-u")
.arg(target_user)
.arg("systemctl")
.arg("--user")
.arg("list-unit-files")
.arg("--type=service")
.arg("--no-pager")
.arg("--plain")
.output()?;
// And user loaded units for target user
let user_units_output = Command::new("sudo")
.arg("-u")
.arg(target_user)
.arg("systemctl")
.arg("--user")
.arg("list-units")
.arg("--type=service")
.arg("--all")
.arg("--no-pager")
.arg("--plain")
.output()?;
if !unit_files_output.status.success() || !units_output.status.success() {
return Err(anyhow::anyhow!("systemctl system command failed"));
}
// User commands might fail if no user session, so check individually
let user_unit_files_success = user_unit_files_output.status.success();
let user_units_success = user_units_output.status.success();
let unit_files_str = String::from_utf8(unit_files_output.stdout)?;
let units_str = String::from_utf8(units_output.stdout)?;
let user_unit_files_str = if user_unit_files_success {
String::from_utf8(user_unit_files_output.stdout).ok()
} else {
None
};
let user_units_str = if user_units_success {
String::from_utf8(user_units_output.stdout).ok()
} else {
None
};
let mut services = Vec::new();
// Use configuration instead of hardcoded values
@ -207,27 +166,6 @@ impl SystemdCollector {
}
}
// Parse user unit files if available
if let Some(user_unit_files_str) = &user_unit_files_str {
for line in user_unit_files_str.lines() {
let fields: Vec<&str> = line.split_whitespace().collect();
if fields.len() >= 2 && fields[0].ends_with(".service") {
let service_name = fields[0].trim_end_matches(".service");
all_service_names.insert(service_name.to_string());
}
}
}
// Parse user loaded units if available
if let Some(user_units_str) = &user_units_str {
for line in user_units_str.lines() {
let fields: Vec<&str> = line.split_whitespace().collect();
if fields.len() >= 4 && fields[0].ends_with(".service") {
let service_name = fields[0].trim_end_matches(".service");
all_service_names.insert(service_name.to_string());
}
}
}
// Now process all discovered services
for service_name in &all_service_names {