From f587b4279771fbe26a0b9c3c118ae241e77ac87a Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Wed, 19 Nov 2025 15:37:33 +0100 Subject: [PATCH] Implement unified SSH command management with dedicated scripts - Replace complex SSH command patterns with simple script calls - Create service-manage script for start/stop operations with proper logging - Create rebuild script equivalent to rebuild_git alias with user feedback - Update dashboard to use unified command pattern: sudo service-manage, sudo rebuild - Simplify backup to use service management: service-manage start borgbackup - Configure sudoers with wildcards for Nix store path compatibility - Remove cmtec references from script names for better genericity - Update version to 0.1.90 --- Cargo.lock | 6 +++--- agent/Cargo.toml | 2 +- dashboard/Cargo.toml | 2 +- dashboard/src/config/mod.rs | 4 ++-- dashboard/src/ui/mod.rs | 16 ++++++---------- shared/Cargo.toml | 2 +- 6 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2860f3b..5b78c1f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" [[package]] name = "cm-dashboard" -version = "0.1.89" +version = "0.1.90" dependencies = [ "anyhow", "chrono", @@ -301,7 +301,7 @@ dependencies = [ [[package]] name = "cm-dashboard-agent" -version = "0.1.89" +version = "0.1.90" dependencies = [ "anyhow", "async-trait", @@ -324,7 +324,7 @@ dependencies = [ [[package]] name = "cm-dashboard-shared" -version = "0.1.89" +version = "0.1.90" dependencies = [ "chrono", "serde", diff --git a/agent/Cargo.toml b/agent/Cargo.toml index b72b91e..4ded3df 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-agent" -version = "0.1.89" +version = "0.1.90" edition = "2021" [dependencies] diff --git a/dashboard/Cargo.toml b/dashboard/Cargo.toml index 5a52a31..e5c8fec 100644 --- a/dashboard/Cargo.toml +++ b/dashboard/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard" -version = "0.1.89" +version = "0.1.90" edition = "2021" [dependencies] diff --git a/dashboard/src/config/mod.rs b/dashboard/src/config/mod.rs index 10d9bc7..85f0f1c 100644 --- a/dashboard/src/config/mod.rs +++ b/dashboard/src/config/mod.rs @@ -55,8 +55,8 @@ pub struct SystemConfig { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct SshConfig { pub rebuild_user: String, - pub rebuild_alias: String, - pub backup_alias: String, + pub rebuild_cmd: String, + pub service_manage_cmd: String, } /// Service log file configuration per host diff --git a/dashboard/src/ui/mod.rs b/dashboard/src/ui/mod.rs index 66ca705..ecd33e9 100644 --- a/dashboard/src/ui/mod.rs +++ b/dashboard/src/ui/mod.rs @@ -225,7 +225,7 @@ impl TuiApp { connection_ip, self.config.ssh.rebuild_user, connection_ip, - self.config.ssh.rebuild_alias + self.config.ssh.rebuild_cmd ); std::process::Command::new("tmux") @@ -249,7 +249,7 @@ impl TuiApp { connection_ip, self.config.ssh.rebuild_user, connection_ip, - self.config.ssh.backup_alias + format!("{} start borgbackup", self.config.ssh.service_manage_cmd) ); std::process::Command::new("tmux") @@ -267,14 +267,12 @@ impl TuiApp { if let (Some(service_name), Some(hostname)) = (self.get_selected_service(), self.current_host.clone()) { let connection_ip = self.get_connection_ip(&hostname); let service_start_command = format!( - "echo 'Starting service: {} on {}' && ssh -tt {}@{} \"bash -c 'sudo systemctl start {} & sudo journalctl -fu {} --since=\\\"1 second ago\\\" --no-pager & while ! systemctl is-active {} >/dev/null 2>&1; do sleep 0.5; done; sudo pkill -f \\\"journalctl -fu {}\\\" 2>/dev/null || true; echo \\\"Press any key to close...\\\"; read -n 1 -s'\" ", + "echo 'Starting service: {} on {}' && ssh -tt {}@{} \"bash -ic '{} start {}'\" && echo 'Press any key to close...' && read -n 1 -s", service_name, hostname, self.config.ssh.rebuild_user, connection_ip, - service_name, - service_name, - service_name, + self.config.ssh.service_manage_cmd, service_name ); @@ -293,14 +291,12 @@ impl TuiApp { if let (Some(service_name), Some(hostname)) = (self.get_selected_service(), self.current_host.clone()) { let connection_ip = self.get_connection_ip(&hostname); let service_stop_command = format!( - "echo 'Stopping service: {} on {}' && ssh -tt {}@{} \"bash -c 'sudo systemctl stop {} & sudo journalctl -fu {} --since=\\\"1 second ago\\\" --no-pager & sleep 1; while systemctl is-active {} >/dev/null 2>&1; do sleep 0.5; done; sleep 2; sudo pkill -f \\\"journalctl -fu {}\\\" 2>/dev/null || true; echo \\\"Press any key to close...\\\"; read -n 1 -s'\" ", + "echo 'Stopping service: {} on {}' && ssh -tt {}@{} \"bash -ic '{} stop {}'\" && echo 'Press any key to close...' && read -n 1 -s", service_name, hostname, self.config.ssh.rebuild_user, connection_ip, - service_name, - service_name, - service_name, + self.config.ssh.service_manage_cmd, service_name ); diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 0900aa6..04bf17d 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-shared" -version = "0.1.89" +version = "0.1.90" edition = "2021" [dependencies]