From 0ca06d2507d1e39299d8ac5b9875078abafff781 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Tue, 18 Nov 2025 16:50:33 +0100 Subject: [PATCH] Add smart service start with automatic log exit - Service start now follows logs in real-time until service becomes active - Automatically stops log following when systemctl reports service as active - Eliminates need for manual Ctrl+C to exit log stream - Shows final service status after startup completes - Background monitoring loop checks service state every second --- Cargo.lock | 6 +++--- agent/Cargo.toml | 2 +- dashboard/Cargo.toml | 2 +- dashboard/src/ui/mod.rs | 4 +++- shared/Cargo.toml | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 71978fc..1c93c57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -270,7 +270,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" [[package]] name = "cm-dashboard" -version = "0.1.74" +version = "0.1.75" dependencies = [ "anyhow", "chrono", @@ -292,7 +292,7 @@ dependencies = [ [[package]] name = "cm-dashboard-agent" -version = "0.1.74" +version = "0.1.75" dependencies = [ "anyhow", "async-trait", @@ -315,7 +315,7 @@ dependencies = [ [[package]] name = "cm-dashboard-shared" -version = "0.1.74" +version = "0.1.75" dependencies = [ "chrono", "serde", diff --git a/agent/Cargo.toml b/agent/Cargo.toml index f667dbf..c4873f1 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-agent" -version = "0.1.75" +version = "0.1.76" edition = "2021" [dependencies] diff --git a/dashboard/Cargo.toml b/dashboard/Cargo.toml index 92d517c..81c532d 100644 --- a/dashboard/Cargo.toml +++ b/dashboard/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard" -version = "0.1.75" +version = "0.1.76" edition = "2021" [dependencies] diff --git a/dashboard/src/ui/mod.rs b/dashboard/src/ui/mod.rs index fa5e0ba..46b8f0a 100644 --- a/dashboard/src/ui/mod.rs +++ b/dashboard/src/ui/mod.rs @@ -274,13 +274,15 @@ 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!( - "bash -c 'cat << \"EOF\"\nService Start: {}.service\nTarget: {} ({})\n\nEOF\nssh -tt {}@{} \"echo \\\"Starting service...\\\" && sudo systemctl start {}.service && echo \\\"Service started! Following logs (Ctrl+C to stop):\\\" && echo \\\"========================================\\\" && sudo journalctl -u {}.service -f --no-pager -n 20\"\necho\necho \"========================================\"\necho \"Operation completed. Press any key to close...\"\necho \"========================================\"\nread -n 1 -s\nexit'", + "bash -c 'cat << \"EOF\"\nService Start: {}.service\nTarget: {} ({})\n\nEOF\nssh -tt {}@{} \"echo \\\"Starting service...\\\" && sudo systemctl start {}.service && echo \\\"Following logs until service is active...\\\" && echo \\\"========================================\\\" && {{ sudo journalctl -u {}.service -f --no-pager -n 10 & JOURNAL_PID=\\$!; while true; do if sudo systemctl is-active {}.service --quiet; then echo; echo \\\"========================================\\\"; echo \\\"Service is now active!\\\"; kill \\$JOURNAL_PID 2>/dev/null; break; fi; sleep 1; done; wait \\$JOURNAL_PID 2>/dev/null; }} && sudo systemctl status {}.service --no-pager -l\"\necho\necho \"========================================\"\necho \"Operation completed. Press any key to close...\"\necho \"========================================\"\nread -n 1 -s\nexit'", service_name, hostname, connection_ip, self.config.ssh.rebuild_user, connection_ip, service_name, + service_name, + service_name, service_name ); diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 6c58ad3..6e6087f 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-shared" -version = "0.1.75" +version = "0.1.76" edition = "2021" [dependencies]