Fix user-stopped flag timing and service transition handling
All checks were successful
Build and Release / build-and-release (push) Successful in 2m9s
All checks were successful
Build and Release / build-and-release (push) Successful in 2m9s
Correct user-stopped service behavior during startup transitions: User-Stopped Flag Timing Fix: - Clear user-stopped flag only when service actually becomes active, not when start command succeeds - Remove premature flag clearing from service control handler - Add automatic flag clearing when service status metrics show active state - Services retain user-stopped status during activating/transitioning states Service Transition Handling: - User-stopped services in activating state now report Status::OK instead of Status::Pending - Prevents host warnings during legitimate service startup transitions - Maintains accurate status reporting throughout service lifecycle - Failed service starts preserve user-stopped flags correctly Journalctl Popup Fix: - Fix terminal corruption when using J key for service logs - Correct command quoting to prevent tmux popup interference - Stable popup display without dashboard interface corruption Result: Clean service startup experience with no false warnings and proper user-stopped tracking throughout the entire service lifecycle. Bump version to v0.1.47
This commit is contained in:
parent
11c9a5f9d2
commit
bd20f0cae1
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.45"
|
version = "0.1.46"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@ -291,7 +291,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.45"
|
version = "0.1.46"
|
||||||
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.45"
|
version = "0.1.46"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.46"
|
version = "0.1.47"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@ -180,6 +180,9 @@ impl Agent {
|
|||||||
let version_metric = self.get_agent_version_metric();
|
let version_metric = self.get_agent_version_metric();
|
||||||
metrics.push(version_metric);
|
metrics.push(version_metric);
|
||||||
|
|
||||||
|
// Check for user-stopped services that are now active and clear their flags
|
||||||
|
self.clear_user_stopped_flags_for_active_services(&metrics);
|
||||||
|
|
||||||
if metrics.is_empty() {
|
if metrics.is_empty() {
|
||||||
debug!("No metrics to broadcast");
|
debug!("No metrics to broadcast");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@ -315,16 +318,8 @@ impl Agent {
|
|||||||
debug!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
debug!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear user-stopped flag AFTER successful start command
|
// Note: User-stopped flag will be cleared by systemd collector
|
||||||
if matches!(action, ServiceAction::UserStart) {
|
// when service actually reaches 'active' state, not here
|
||||||
info!("Clearing user-stopped flag for service '{}' after successful start", service_name);
|
|
||||||
if let Err(e) = self.service_tracker.clear_user_stopped(service_name) {
|
|
||||||
error!("Failed to clear user-stopped flag: {}", e);
|
|
||||||
} else {
|
|
||||||
// Sync to global tracker
|
|
||||||
UserStoppedServiceTracker::update_global(&self.service_tracker);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||||
error!("Service {} {} failed: {}", service_name, action_str, stderr);
|
error!("Service {} {} failed: {}", service_name, action_str, stderr);
|
||||||
@ -344,4 +339,33 @@ impl Agent {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Check metrics for user-stopped services that are now active and clear their flags
|
||||||
|
fn clear_user_stopped_flags_for_active_services(&mut self, metrics: &[Metric]) {
|
||||||
|
for metric in metrics {
|
||||||
|
// Look for service status metrics that are active
|
||||||
|
if metric.name.starts_with("service_") && metric.name.ends_with("_status") {
|
||||||
|
if let MetricValue::String(status) = &metric.value {
|
||||||
|
if status == "active" {
|
||||||
|
// Extract service name from metric name (service_nginx_status -> nginx)
|
||||||
|
let service_name = metric.name
|
||||||
|
.strip_prefix("service_")
|
||||||
|
.and_then(|s| s.strip_suffix("_status"))
|
||||||
|
.unwrap_or("");
|
||||||
|
|
||||||
|
if !service_name.is_empty() && UserStoppedServiceTracker::is_service_user_stopped(service_name) {
|
||||||
|
info!("Service '{}' is now active - clearing user-stopped flag", service_name);
|
||||||
|
if let Err(e) = self.service_tracker.clear_user_stopped(service_name) {
|
||||||
|
error!("Failed to clear user-stopped flag for '{}': {}", service_name, e);
|
||||||
|
} else {
|
||||||
|
// Sync to global tracker
|
||||||
|
UserStoppedServiceTracker::update_global(&self.service_tracker);
|
||||||
|
debug!("Cleared user-stopped flag for service '{}'", service_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -357,7 +357,15 @@ impl SystemdCollector {
|
|||||||
/// Calculate service status, taking user-stopped services into account
|
/// Calculate service status, taking user-stopped services into account
|
||||||
fn calculate_service_status(&self, service_name: &str, active_status: &str) -> Status {
|
fn calculate_service_status(&self, service_name: &str, active_status: &str) -> Status {
|
||||||
match active_status.to_lowercase().as_str() {
|
match active_status.to_lowercase().as_str() {
|
||||||
"active" => Status::Ok,
|
"active" => {
|
||||||
|
// If service is now active and was marked as user-stopped, clear the flag
|
||||||
|
if UserStoppedServiceTracker::is_service_user_stopped(service_name) {
|
||||||
|
debug!("Service '{}' is now active - clearing user-stopped flag", service_name);
|
||||||
|
// Note: We can't directly clear here because this is a read-only context
|
||||||
|
// The agent will need to handle this differently
|
||||||
|
}
|
||||||
|
Status::Ok
|
||||||
|
},
|
||||||
"inactive" | "dead" => {
|
"inactive" | "dead" => {
|
||||||
// Check if this service was stopped by user action
|
// Check if this service was stopped by user action
|
||||||
if UserStoppedServiceTracker::is_service_user_stopped(service_name) {
|
if UserStoppedServiceTracker::is_service_user_stopped(service_name) {
|
||||||
@ -368,7 +376,15 @@ impl SystemdCollector {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"failed" | "error" => Status::Critical,
|
"failed" | "error" => Status::Critical,
|
||||||
"activating" | "deactivating" | "reloading" | "start" | "stop" | "restart" => Status::Pending,
|
"activating" | "deactivating" | "reloading" | "start" | "stop" | "restart" => {
|
||||||
|
// For user-stopped services that are transitioning, keep them as OK during transition
|
||||||
|
if UserStoppedServiceTracker::is_service_user_stopped(service_name) {
|
||||||
|
debug!("Service '{}' is transitioning but was user-stopped - treating as OK", service_name);
|
||||||
|
Status::Ok
|
||||||
|
} else {
|
||||||
|
Status::Pending
|
||||||
|
}
|
||||||
|
},
|
||||||
_ => Status::Unknown,
|
_ => Status::Unknown,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.46"
|
version = "0.1.47"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@ -302,7 +302,7 @@ ssh -tt {}@{} 'bash -ic {}'",
|
|||||||
.arg("-h")
|
.arg("-h")
|
||||||
.arg("80%")
|
.arg("80%")
|
||||||
.arg("-t")
|
.arg("-t")
|
||||||
.arg(format!("Logs: {}.service", service_name))
|
.arg(format!("Logs: {}", service_name))
|
||||||
.arg(&journalctl_command)
|
.arg(&journalctl_command)
|
||||||
.spawn()
|
.spawn()
|
||||||
.ok(); // Ignore errors, tmux will handle them
|
.ok(); // Ignore errors, tmux will handle them
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.46"
|
version = "0.1.47"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user