Fix service discovery to show all configured services regardless of state
All checks were successful
Build and Release / build-and-release (push) Successful in 2m7s

Changed service discovery from 'systemctl list-units --all' to 'systemctl list-unit-files'
to ensure ALL service unit files are discovered, including services that have never been started.

Changes:
- Updated systemctl command to use list-unit-files instead of list-units --all
- Modified parsing logic to handle unit file format (2 fields vs 4 fields)
- Set placeholder values in discovery cache, actual runtime status fetched during collection
- This ensures all configured services (like inactive ARK servers) appear in dashboard

The issue was that list-units --all only shows services systemd has loaded/attempted to load,
but list-unit-files shows ALL service unit files regardless of their runtime state.
This commit is contained in:
Christoffer Martinsson 2025-10-28 15:41:58 +01:00
parent a847674004
commit 078c30a592
6 changed files with 17 additions and 21 deletions

6
Cargo.lock generated
View File

@ -270,7 +270,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
[[package]]
name = "cm-dashboard"
version = "0.1.29"
version = "0.1.30"
dependencies = [
"anyhow",
"chrono",
@ -291,7 +291,7 @@ dependencies = [
[[package]]
name = "cm-dashboard-agent"
version = "0.1.29"
version = "0.1.30"
dependencies = [
"anyhow",
"async-trait",
@ -314,7 +314,7 @@ dependencies = [
[[package]]
name = "cm-dashboard-shared"
version = "0.1.29"
version = "0.1.30"
dependencies = [
"chrono",
"serde",

View File

@ -1,6 +1,6 @@
[package]
name = "cm-dashboard-agent"
version = "0.1.30"
version = "0.1.31"
edition = "2021"
[dependencies]

View File

@ -136,11 +136,10 @@ impl SystemdCollector {
/// Auto-discover interesting services to monitor (internal version that doesn't update state)
fn discover_services_internal(&self) -> Result<(Vec<String>, std::collections::HashMap<String, ServiceStatusInfo>)> {
debug!("Starting systemd service discovery with status caching");
// Get all services (includes inactive, running, failed - everything)
// Get all service unit files (includes services that have never been started)
let units_output = Command::new("systemctl")
.arg("list-units")
.arg("list-unit-files")
.arg("--type=service")
.arg("--all")
.arg("--no-pager")
.arg("--plain")
.output()?;
@ -162,23 +161,20 @@ impl SystemdCollector {
for line in units_str.lines() {
let fields: Vec<&str> = line.split_whitespace().collect();
if fields.len() >= 4 && fields[0].ends_with(".service") {
if fields.len() >= 2 && fields[0].ends_with(".service") {
let service_name = fields[0].trim_end_matches(".service");
let unit_file_state = fields.get(1).unwrap_or(&"unknown").to_string();
// Extract status information from systemctl list-units output
let load_state = fields.get(1).unwrap_or(&"unknown").to_string();
let active_state = fields.get(2).unwrap_or(&"unknown").to_string();
let sub_state = fields.get(3).unwrap_or(&"unknown").to_string();
// Cache the status information
// For unit files, we don't have runtime status info yet - will be fetched individually
// Set placeholder values for status cache (actual status will be fetched when collecting metrics)
status_cache.insert(service_name.to_string(), ServiceStatusInfo {
load_state: load_state.clone(),
active_state: active_state.clone(),
sub_state: sub_state.clone(),
load_state: "unknown".to_string(), // Will be determined when we check individual status
active_state: "unknown".to_string(), // Will be determined when we check individual status
sub_state: unit_file_state.clone(), // Use unit file state as placeholder
});
all_service_names.insert(service_name.to_string());
debug!("Parsed service: {} (load:{}, active:{}, sub:{})", service_name, load_state, active_state, sub_state);
debug!("Found service unit file: {} (file_state: {})", service_name, unit_file_state);
}
}

View File

@ -1,6 +1,6 @@
[package]
name = "cm-dashboard"
version = "0.1.30"
version = "0.1.31"
edition = "2021"
[dependencies]

View File

@ -14,7 +14,7 @@ use app::Dashboard;
/// Get hardcoded version
fn get_version() -> &'static str {
"v0.1.30"
"v0.1.31"
}
/// Check if running inside tmux session

View File

@ -1,6 +1,6 @@
[package]
name = "cm-dashboard-shared"
version = "0.1.30"
version = "0.1.31"
edition = "2021"
[dependencies]