Remove service restart functionality and make R always rebuild host
All checks were successful
Build and Release / build-and-release (push) Successful in 2m6s

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.
This commit is contained in:
Christoffer Martinsson 2025-10-28 15:26:15 +01:00
parent 2618f6b62f
commit a847674004
11 changed files with 26 additions and 57 deletions

6
Cargo.lock generated
View File

@ -270,7 +270,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
[[package]] [[package]]
name = "cm-dashboard" name = "cm-dashboard"
version = "0.1.28" version = "0.1.29"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chrono", "chrono",
@ -291,7 +291,7 @@ dependencies = [
[[package]] [[package]]
name = "cm-dashboard-agent" name = "cm-dashboard-agent"
version = "0.1.28" version = "0.1.29"
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.28" version = "0.1.29"
dependencies = [ dependencies = [
"chrono", "chrono",
"serde", "serde",

View File

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

View File

@ -274,7 +274,6 @@ impl Agent {
let action_str = match action { let action_str = match action {
ServiceAction::Start => "start", ServiceAction::Start => "start",
ServiceAction::Stop => "stop", ServiceAction::Stop => "stop",
ServiceAction::Restart => "restart",
ServiceAction::Status => "status", ServiceAction::Status => "status",
}; };
@ -299,7 +298,7 @@ impl Agent {
} }
// Force refresh metrics after service control to update service status // 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"); info!("Triggering immediate metric refresh after service control");
if let Err(e) = self.collect_metrics_only().await { if let Err(e) = self.collect_metrics_only().await {
error!("Failed to refresh metrics after service control: {}", e); error!("Failed to refresh metrics after service control: {}", e);

View File

@ -112,6 +112,5 @@ pub enum AgentCommand {
pub enum ServiceAction { pub enum ServiceAction {
Start, Start,
Stop, Stop,
Restart,
Status, Status,
} }

View File

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

View File

@ -294,14 +294,6 @@ impl Dashboard {
/// Execute a UI command by sending it to the appropriate agent /// Execute a UI command by sending it to the appropriate agent
async fn execute_ui_command(&self, command: UiCommand) -> Result<()> { async fn execute_ui_command(&self, command: UiCommand) -> Result<()> {
match command { 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 } => { UiCommand::ServiceStart { hostname, service_name } => {
info!("Sending start command for service {} on {}", service_name, hostname); info!("Sending start command for service {} on {}", service_name, hostname);
let agent_command = AgentCommand::ServiceControl { let agent_command = AgentCommand::ServiceControl {

View File

@ -35,7 +35,6 @@ pub enum AgentCommand {
pub enum ServiceAction { pub enum ServiceAction {
Start, Start,
Stop, Stop,
Restart,
Status, Status,
} }

View File

@ -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.29" "v0.1.30"
} }
/// Check if running inside tmux session /// Check if running inside tmux session

View File

@ -22,7 +22,6 @@ use widgets::{BackupWidget, ServicesWidget, SystemWidget, Widget};
/// Commands that can be triggered from the UI /// Commands that can be triggered from the UI
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum UiCommand { pub enum UiCommand {
ServiceRestart { hostname: String, service_name: String },
ServiceStart { hostname: String, service_name: String }, ServiceStart { hostname: String, service_name: String },
ServiceStop { hostname: String, service_name: String }, ServiceStop { hostname: String, service_name: String },
TriggerBackup { hostname: String }, TriggerBackup { hostname: String },
@ -32,7 +31,6 @@ pub enum UiCommand {
/// Types of commands for status tracking /// Types of commands for status tracking
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum CommandType { pub enum CommandType {
ServiceRestart,
ServiceStart, ServiceStart,
ServiceStop, ServiceStop,
BackupTrigger, BackupTrigger,
@ -256,35 +254,20 @@ impl TuiApp {
self.navigate_host(1); self.navigate_host(1);
} }
KeyCode::Char('r') => { KeyCode::Char('r') => {
match self.focused_panel { // System rebuild command - works on any panel for current host
PanelType::System => { if let Some(hostname) = self.current_host.clone() {
// Simple tmux popup with SSH rebuild using configured user and alias // Launch tmux popup with SSH using config values
if let Some(hostname) = self.current_host.clone() { let ssh_command = format!(
// Launch tmux popup with SSH using config values "ssh -tt {}@{} 'bash -ic {}'",
let ssh_command = format!( self.config.ssh.rebuild_user,
"ssh -tt {}@{} 'bash -ic {}'", hostname,
self.config.ssh.rebuild_user, self.config.ssh.rebuild_alias
hostname, );
self.config.ssh.rebuild_alias std::process::Command::new("tmux")
); .arg("display-popup")
std::process::Command::new("tmux") .arg(&ssh_command)
.arg("display-popup") .spawn()
.arg(&ssh_command) .ok(); // Ignore errors, tmux will handle them
.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");
}
} }
} }
KeyCode::Char('s') => { KeyCode::Char('s') => {
@ -431,7 +414,6 @@ impl TuiApp {
let should_execute = match (&command_type, current_status.as_deref()) { let should_execute = match (&command_type, current_status.as_deref()) {
(CommandType::ServiceStart, Some("inactive") | Some("failed") | Some("dead")) => true, (CommandType::ServiceStart, Some("inactive") | Some("failed") | Some("dead")) => true,
(CommandType::ServiceStop, Some("active")) => true, (CommandType::ServiceStop, Some("active")) => true,
(CommandType::ServiceRestart, Some("active") | Some("inactive") | Some("failed") | Some("dead")) => true,
(CommandType::ServiceStart, Some("active")) => { (CommandType::ServiceStart, Some("active")) => {
// Already running - don't execute // Already running - don't execute
false false
@ -477,7 +459,6 @@ impl TuiApp {
let expected_change = match command_type { let expected_change = match command_type {
CommandType::ServiceStart => &new_status == "active", CommandType::ServiceStart => &new_status == "active",
CommandType::ServiceStop => &new_status != "active", CommandType::ServiceStop => &new_status != "active",
CommandType::ServiceRestart => true, // Any change indicates restart completed
_ => false, _ => false,
}; };
@ -754,19 +735,19 @@ impl TuiApp {
// Scroll shortcuts (always available) // Scroll shortcuts (always available)
shortcuts.push("↑↓: Scroll".to_string()); shortcuts.push("↑↓: Scroll".to_string());
// Global rebuild shortcut (works on any panel)
shortcuts.push("R: Rebuild Host".to_string());
// Panel-specific shortcuts // Panel-specific shortcuts
match self.focused_panel { match self.focused_panel {
PanelType::System => {
shortcuts.push("R: Rebuild".to_string());
}
PanelType::Services => { PanelType::Services => {
shortcuts.push("S: Start".to_string()); shortcuts.push("S: Start".to_string());
shortcuts.push("Shift+S: Stop".to_string()); shortcuts.push("Shift+S: Stop".to_string());
shortcuts.push("R: Restart".to_string());
} }
PanelType::Backup => { PanelType::Backup => {
shortcuts.push("B: Trigger Backup".to_string()); shortcuts.push("B: Trigger Backup".to_string());
} }
_ => {}
} }
// Always show quit // Always show quit

View File

@ -134,7 +134,6 @@ impl ServicesWidget {
if let Some((command_type, _original_status, _start_time)) = pending_transitions.get(service_name) { if let Some((command_type, _original_status, _start_time)) = pending_transitions.get(service_name) {
// Show transitional icons for pending commands // Show transitional icons for pending commands
let (icon, status_text) = match command_type { let (icon, status_text) = match command_type {
CommandType::ServiceRestart => ("", "restarting"),
CommandType::ServiceStart => ("", "starting"), CommandType::ServiceStart => ("", "starting"),
CommandType::ServiceStop => ("", "stopping"), 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 _ => return (StatusIcons::get_icon(info.widget_status).to_string(), info.status.clone(), Theme::status_color(info.widget_status)), // Not a service command

View File

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