From 2384f7f9b9cea53bc4efa0ba2aea897ed79b437b Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Thu, 20 Nov 2025 11:00:38 +0100 Subject: [PATCH] Unify log viewing with configurable script command Replace separate J/L keys with single L key that calls configurable service_logs_cmd from dashboard config. Script handles both journalctl and custom log files automatically based on service configuration. Update status bar to show all available keybindings including previously missing backup and terminal commands. --- agent/Cargo.toml | 2 +- dashboard/Cargo.toml | 2 +- dashboard/src/config/mod.rs | 1 + dashboard/src/ui/mod.rs | 46 ++++++++----------------------------- shared/Cargo.toml | 2 +- 5 files changed, 13 insertions(+), 40 deletions(-) diff --git a/agent/Cargo.toml b/agent/Cargo.toml index ef426fe..dae31f6 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-agent" -version = "0.1.92" +version = "0.1.93" edition = "2021" [dependencies] diff --git a/dashboard/Cargo.toml b/dashboard/Cargo.toml index 18ba33b..8bc4ab5 100644 --- a/dashboard/Cargo.toml +++ b/dashboard/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard" -version = "0.1.92" +version = "0.1.93" edition = "2021" [dependencies] diff --git a/dashboard/src/config/mod.rs b/dashboard/src/config/mod.rs index 85f0f1c..bf1eff9 100644 --- a/dashboard/src/config/mod.rs +++ b/dashboard/src/config/mod.rs @@ -57,6 +57,7 @@ pub struct SshConfig { pub rebuild_user: String, pub rebuild_cmd: String, pub service_manage_cmd: String, + pub service_logs_cmd: String, } /// Service log file configuration per host diff --git a/dashboard/src/ui/mod.rs b/dashboard/src/ui/mod.rs index 09132f1..59e9226 100644 --- a/dashboard/src/ui/mod.rs +++ b/dashboard/src/ui/mod.rs @@ -310,16 +310,15 @@ impl TuiApp { .ok(); // Ignore errors, tmux will handle them } } - KeyCode::Char('J') => { - // Show service logs via journalctl in tmux split window + KeyCode::Char('L') => { + // Show service logs via script in tmux split window if let (Some(service_name), Some(hostname)) = (self.get_selected_service(), self.current_host.clone()) { let connection_ip = self.get_connection_ip(&hostname); - let journalctl_command = format!( - "echo 'Viewing logs for service: {} on {}' && ssh -tt {}@{} 'sudo journalctl -u {}.service -f --no-pager -n 50'", - service_name, - hostname, + let logs_command = format!( + "ssh -tt {}@{} '{} {}'", self.config.ssh.rebuild_user, connection_ip, + self.config.ssh.service_logs_cmd, service_name ); @@ -328,39 +327,11 @@ impl TuiApp { .arg("-v") .arg("-p") .arg("30") - .arg(&journalctl_command) + .arg(&logs_command) .spawn() .ok(); // Ignore errors, tmux will handle them } } - KeyCode::Char('L') => { - // Show custom service log file in tmux split window - if let (Some(service_name), Some(hostname)) = (self.get_selected_service(), self.current_host.clone()) { - // Check if this service has a custom log file configured - if let Some(host_logs) = self.config.service_logs.get(&hostname) { - if let Some(log_config) = host_logs.iter().find(|config| config.service_name == service_name) { - let connection_ip = self.get_connection_ip(&hostname); - let tail_command = format!( - "echo 'Viewing custom logs for service: {} on {}' && ssh -tt {}@{} 'sudo tail -n 50 -f {}'", - service_name, - hostname, - self.config.ssh.rebuild_user, - connection_ip, - log_config.log_file_path - ); - - std::process::Command::new("tmux") - .arg("split-window") - .arg("-v") - .arg("-p") - .arg("30") - .arg(&tail_command) - .spawn() - .ok(); // Ignore errors, tmux will handle them - } - } - } - } KeyCode::Char('w') => { // Wake on LAN for offline hosts if let Some(hostname) = self.current_host.clone() { @@ -747,9 +718,10 @@ impl TuiApp { shortcuts.push("Tab: Host".to_string()); shortcuts.push("↑↓/jk: Select".to_string()); shortcuts.push("r: Rebuild".to_string()); + shortcuts.push("B: Backup".to_string()); shortcuts.push("s/S: Start/Stop".to_string()); - shortcuts.push("J: Logs".to_string()); - shortcuts.push("L: Custom".to_string()); + shortcuts.push("L: Logs".to_string()); + shortcuts.push("t: Terminal".to_string()); shortcuts.push("w: Wake".to_string()); // Always show quit diff --git a/shared/Cargo.toml b/shared/Cargo.toml index c035f71..f957905 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-shared" -version = "0.1.92" +version = "0.1.93" edition = "2021" [dependencies]