From a847674004d89b447700bab11df572907d4fcaca Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Tue, 28 Oct 2025 15:26:15 +0100 Subject: [PATCH] Remove service restart functionality and make R always rebuild host Simplified keyboard controls by removing service restart functionality: - Removed 'r' key restart functionality from Services panel - Made 'R' key always trigger system rebuild regardless of focused panel - Updated context shortcuts to show 'R: Rebuild Host' globally - Removed all ServiceRestart enum variants and associated code: - UiCommand::ServiceRestart - CommandType::ServiceRestart - ServiceAction::Restart - Cleaned up pending transition logic to only handle Start/Stop commands The 'R' key now consistently rebuilds the current host from any panel, while 's' and 'S' continue to handle service start/stop in Services panel. --- Cargo.lock | 6 +-- agent/Cargo.toml | 2 +- agent/src/agent.rs | 3 +- agent/src/communication/mod.rs | 1 - dashboard/Cargo.toml | 2 +- dashboard/src/app.rs | 8 ---- dashboard/src/communication/mod.rs | 1 - dashboard/src/main.rs | 2 +- dashboard/src/ui/mod.rs | 55 +++++++++------------------- dashboard/src/ui/widgets/services.rs | 1 - shared/Cargo.toml | 2 +- 11 files changed, 26 insertions(+), 57 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4115b58..473a07c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -270,7 +270,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" [[package]] name = "cm-dashboard" -version = "0.1.28" +version = "0.1.29" dependencies = [ "anyhow", "chrono", @@ -291,7 +291,7 @@ dependencies = [ [[package]] name = "cm-dashboard-agent" -version = "0.1.28" +version = "0.1.29" dependencies = [ "anyhow", "async-trait", @@ -314,7 +314,7 @@ dependencies = [ [[package]] name = "cm-dashboard-shared" -version = "0.1.28" +version = "0.1.29" dependencies = [ "chrono", "serde", diff --git a/agent/Cargo.toml b/agent/Cargo.toml index d1981b7..75c4d90 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-agent" -version = "0.1.29" +version = "0.1.30" edition = "2021" [dependencies] diff --git a/agent/src/agent.rs b/agent/src/agent.rs index 3826bbc..d2dd1a6 100644 --- a/agent/src/agent.rs +++ b/agent/src/agent.rs @@ -274,7 +274,6 @@ impl Agent { let action_str = match action { ServiceAction::Start => "start", ServiceAction::Stop => "stop", - ServiceAction::Restart => "restart", ServiceAction::Status => "status", }; @@ -299,7 +298,7 @@ impl Agent { } // Force refresh metrics after service control to update service status - if matches!(action, ServiceAction::Start | ServiceAction::Stop | ServiceAction::Restart) { + if matches!(action, ServiceAction::Start | ServiceAction::Stop) { info!("Triggering immediate metric refresh after service control"); if let Err(e) = self.collect_metrics_only().await { error!("Failed to refresh metrics after service control: {}", e); diff --git a/agent/src/communication/mod.rs b/agent/src/communication/mod.rs index 4a5e5af..0cbe1a0 100644 --- a/agent/src/communication/mod.rs +++ b/agent/src/communication/mod.rs @@ -112,6 +112,5 @@ pub enum AgentCommand { pub enum ServiceAction { Start, Stop, - Restart, Status, } diff --git a/dashboard/Cargo.toml b/dashboard/Cargo.toml index eec3652..ba22057 100644 --- a/dashboard/Cargo.toml +++ b/dashboard/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard" -version = "0.1.29" +version = "0.1.30" edition = "2021" [dependencies] diff --git a/dashboard/src/app.rs b/dashboard/src/app.rs index 7ca4a67..d39aea1 100644 --- a/dashboard/src/app.rs +++ b/dashboard/src/app.rs @@ -294,14 +294,6 @@ impl Dashboard { /// Execute a UI command by sending it to the appropriate agent async fn execute_ui_command(&self, command: UiCommand) -> Result<()> { match command { - UiCommand::ServiceRestart { hostname, service_name } => { - info!("Sending restart command for service {} on {}", service_name, hostname); - let agent_command = AgentCommand::ServiceControl { - service_name, - action: ServiceAction::Restart, - }; - self.zmq_command_sender.send_command(&hostname, agent_command).await?; - } UiCommand::ServiceStart { hostname, service_name } => { info!("Sending start command for service {} on {}", service_name, hostname); let agent_command = AgentCommand::ServiceControl { diff --git a/dashboard/src/communication/mod.rs b/dashboard/src/communication/mod.rs index 25c9652..da93bdb 100644 --- a/dashboard/src/communication/mod.rs +++ b/dashboard/src/communication/mod.rs @@ -35,7 +35,6 @@ pub enum AgentCommand { pub enum ServiceAction { Start, Stop, - Restart, Status, } diff --git a/dashboard/src/main.rs b/dashboard/src/main.rs index 1035992..21db0e0 100644 --- a/dashboard/src/main.rs +++ b/dashboard/src/main.rs @@ -14,7 +14,7 @@ use app::Dashboard; /// Get hardcoded version fn get_version() -> &'static str { - "v0.1.29" + "v0.1.30" } /// Check if running inside tmux session diff --git a/dashboard/src/ui/mod.rs b/dashboard/src/ui/mod.rs index cbb0b06..c6f5503 100644 --- a/dashboard/src/ui/mod.rs +++ b/dashboard/src/ui/mod.rs @@ -22,7 +22,6 @@ use widgets::{BackupWidget, ServicesWidget, SystemWidget, Widget}; /// Commands that can be triggered from the UI #[derive(Debug, Clone)] pub enum UiCommand { - ServiceRestart { hostname: String, service_name: String }, ServiceStart { hostname: String, service_name: String }, ServiceStop { hostname: String, service_name: String }, TriggerBackup { hostname: String }, @@ -32,7 +31,6 @@ pub enum UiCommand { /// Types of commands for status tracking #[derive(Debug, Clone)] pub enum CommandType { - ServiceRestart, ServiceStart, ServiceStop, BackupTrigger, @@ -256,35 +254,20 @@ impl TuiApp { self.navigate_host(1); } KeyCode::Char('r') => { - match self.focused_panel { - PanelType::System => { - // Simple tmux popup with SSH rebuild using configured user and alias - if let Some(hostname) = self.current_host.clone() { - // Launch tmux popup with SSH using config values - let ssh_command = format!( - "ssh -tt {}@{} 'bash -ic {}'", - self.config.ssh.rebuild_user, - hostname, - self.config.ssh.rebuild_alias - ); - std::process::Command::new("tmux") - .arg("display-popup") - .arg(&ssh_command) - .spawn() - .ok(); // Ignore errors, tmux will handle them - } - } - PanelType::Services => { - // Service restart command - if let (Some(service_name), Some(hostname)) = (self.get_selected_service(), self.current_host.clone()) { - if self.start_command(&hostname, CommandType::ServiceRestart, service_name.clone()) { - return Ok(Some(UiCommand::ServiceRestart { hostname, service_name })); - } - } - } - _ => { - info!("Manual refresh requested"); - } + // System rebuild command - works on any panel for current host + if let Some(hostname) = self.current_host.clone() { + // Launch tmux popup with SSH using config values + let ssh_command = format!( + "ssh -tt {}@{} 'bash -ic {}'", + self.config.ssh.rebuild_user, + hostname, + self.config.ssh.rebuild_alias + ); + std::process::Command::new("tmux") + .arg("display-popup") + .arg(&ssh_command) + .spawn() + .ok(); // Ignore errors, tmux will handle them } } KeyCode::Char('s') => { @@ -431,7 +414,6 @@ impl TuiApp { let should_execute = match (&command_type, current_status.as_deref()) { (CommandType::ServiceStart, Some("inactive") | Some("failed") | Some("dead")) => true, (CommandType::ServiceStop, Some("active")) => true, - (CommandType::ServiceRestart, Some("active") | Some("inactive") | Some("failed") | Some("dead")) => true, (CommandType::ServiceStart, Some("active")) => { // Already running - don't execute false @@ -477,7 +459,6 @@ impl TuiApp { let expected_change = match command_type { CommandType::ServiceStart => &new_status == "active", CommandType::ServiceStop => &new_status != "active", - CommandType::ServiceRestart => true, // Any change indicates restart completed _ => false, }; @@ -754,19 +735,19 @@ impl TuiApp { // Scroll shortcuts (always available) shortcuts.push("↑↓: Scroll".to_string()); + // Global rebuild shortcut (works on any panel) + shortcuts.push("R: Rebuild Host".to_string()); + // Panel-specific shortcuts match self.focused_panel { - PanelType::System => { - shortcuts.push("R: Rebuild".to_string()); - } PanelType::Services => { shortcuts.push("S: Start".to_string()); shortcuts.push("Shift+S: Stop".to_string()); - shortcuts.push("R: Restart".to_string()); } PanelType::Backup => { shortcuts.push("B: Trigger Backup".to_string()); } + _ => {} } // Always show quit diff --git a/dashboard/src/ui/widgets/services.rs b/dashboard/src/ui/widgets/services.rs index 2425933..12316b2 100644 --- a/dashboard/src/ui/widgets/services.rs +++ b/dashboard/src/ui/widgets/services.rs @@ -134,7 +134,6 @@ impl ServicesWidget { if let Some((command_type, _original_status, _start_time)) = pending_transitions.get(service_name) { // Show transitional icons for pending commands let (icon, status_text) = match command_type { - CommandType::ServiceRestart => ("↻", "restarting"), CommandType::ServiceStart => ("↑", "starting"), CommandType::ServiceStop => ("↓", "stopping"), _ => return (StatusIcons::get_icon(info.widget_status).to_string(), info.status.clone(), Theme::status_color(info.widget_status)), // Not a service command diff --git a/shared/Cargo.toml b/shared/Cargo.toml index bb9438d..9f54829 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-shared" -version = "0.1.29" +version = "0.1.30" edition = "2021" [dependencies]