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
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:
parent
a847674004
commit
078c30a592
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -270,7 +270,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.29"
|
version = "0.1.30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@ -291,7 +291,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.29"
|
version = "0.1.30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@ -314,7 +314,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.29"
|
version = "0.1.30"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.30"
|
version = "0.1.31"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@ -136,11 +136,10 @@ impl SystemdCollector {
|
|||||||
/// Auto-discover interesting services to monitor (internal version that doesn't update state)
|
/// 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>)> {
|
fn discover_services_internal(&self) -> Result<(Vec<String>, std::collections::HashMap<String, ServiceStatusInfo>)> {
|
||||||
debug!("Starting systemd service discovery with status caching");
|
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")
|
let units_output = Command::new("systemctl")
|
||||||
.arg("list-units")
|
.arg("list-unit-files")
|
||||||
.arg("--type=service")
|
.arg("--type=service")
|
||||||
.arg("--all")
|
|
||||||
.arg("--no-pager")
|
.arg("--no-pager")
|
||||||
.arg("--plain")
|
.arg("--plain")
|
||||||
.output()?;
|
.output()?;
|
||||||
@ -162,23 +161,20 @@ impl SystemdCollector {
|
|||||||
|
|
||||||
for line in units_str.lines() {
|
for line in units_str.lines() {
|
||||||
let fields: Vec<&str> = line.split_whitespace().collect();
|
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 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
|
// For unit files, we don't have runtime status info yet - will be fetched individually
|
||||||
let load_state = fields.get(1).unwrap_or(&"unknown").to_string();
|
// Set placeholder values for status cache (actual status will be fetched when collecting metrics)
|
||||||
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
|
|
||||||
status_cache.insert(service_name.to_string(), ServiceStatusInfo {
|
status_cache.insert(service_name.to_string(), ServiceStatusInfo {
|
||||||
load_state: load_state.clone(),
|
load_state: "unknown".to_string(), // Will be determined when we check individual status
|
||||||
active_state: active_state.clone(),
|
active_state: "unknown".to_string(), // Will be determined when we check individual status
|
||||||
sub_state: sub_state.clone(),
|
sub_state: unit_file_state.clone(), // Use unit file state as placeholder
|
||||||
});
|
});
|
||||||
|
|
||||||
all_service_names.insert(service_name.to_string());
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.30"
|
version = "0.1.31"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@ -14,7 +14,7 @@ use app::Dashboard;
|
|||||||
|
|
||||||
/// Get hardcoded version
|
/// Get hardcoded version
|
||||||
fn get_version() -> &'static str {
|
fn get_version() -> &'static str {
|
||||||
"v0.1.30"
|
"v0.1.31"
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if running inside tmux session
|
/// Check if running inside tmux session
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.30"
|
version = "0.1.31"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user