From c326711d7cbd3a1b077e8de2d55966112d8e713a Mon Sep 17 00:00:00 2001 From: anonpenguin23 Date: Fri, 31 Oct 2025 14:34:03 +0200 Subject: [PATCH] feat: enhance service management and configuration options - Updated service startup logic to include a helper function for starting or restarting services, improving reliability and clarity in service management. - Added new configuration options for cluster synchronization, peer inactivity limits, and minimum cluster size in the config_commands.go file, enhancing cluster management capabilities. --- pkg/cli/config_commands.go | 6 +++++ pkg/cli/setup.go | 49 +++++++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/pkg/cli/config_commands.go b/pkg/cli/config_commands.go index 4ae5674..23fed88 100644 --- a/pkg/cli/config_commands.go +++ b/pkg/cli/config_commands.go @@ -422,6 +422,9 @@ database: rqlite_port: %d rqlite_raft_port: %d rqlite_join_address: "%s" + cluster_sync_interval: "30s" + peer_inactivity_limit: "24h" + min_cluster_size: 1 discovery: %s @@ -466,6 +469,9 @@ database: rqlite_port: %d rqlite_raft_port: %d rqlite_join_address: "" + cluster_sync_interval: "30s" + peer_inactivity_limit: "24h" + min_cluster_size: 1 discovery: bootstrap_peers: [] diff --git a/pkg/cli/setup.go b/pkg/cli/setup.go index ad527f1..b78045b 100644 --- a/pkg/cli/setup.go +++ b/pkg/cli/setup.go @@ -960,19 +960,46 @@ WantedBy=multi-user.target } func startServices() { - fmt.Printf("🚀 Starting services...\n") + fmt.Printf("🚀 Starting/Restarting services...\n") - // Start node - if err := exec.Command("systemctl", "start", "debros-node").Run(); err != nil { - fmt.Fprintf(os.Stderr, "⚠️ Failed to start node service: %v\n", err) - } else { - fmt.Printf(" ✓ Node service started\n") + // Helper function to start or restart a service + startOrRestartService := func(serviceName string) { + // Check if service is active/running + checkCmd := exec.Command("systemctl", "is-active", "--quiet", serviceName) + isRunning := checkCmd.Run() == nil + + if isRunning { + // Service is running, restart it + fmt.Printf(" Restarting %s service...\n", serviceName) + if err := exec.Command("systemctl", "restart", serviceName).Run(); err != nil { + fmt.Fprintf(os.Stderr, "⚠️ Failed to restart %s service: %v\n", serviceName, err) + } else { + fmt.Printf(" ✓ %s service restarted\n", serviceName) + } + } else { + // Service is not running, start it + fmt.Printf(" Starting %s service...\n", serviceName) + if err := exec.Command("systemctl", "start", serviceName).Run(); err != nil { + fmt.Fprintf(os.Stderr, "⚠️ Failed to start %s service: %v\n", serviceName, err) + } else { + fmt.Printf(" ✓ %s service started\n", serviceName) + } + } } - // Start gateway - if err := exec.Command("systemctl", "start", "debros-gateway").Run(); err != nil { - fmt.Fprintf(os.Stderr, "⚠️ Failed to start gateway service: %v\n", err) - } else { - fmt.Printf(" ✓ Gateway service started\n") + // Start or restart node service + startOrRestartService("debros-node") + + // Start or restart gateway service + startOrRestartService("debros-gateway") + + // Also restart Anon service if it's running (to pick up any config changes) + if exec.Command("systemctl", "is-active", "--quiet", "anon").Run() == nil { + fmt.Printf(" Restarting Anon service to pick up config changes...\n") + if err := exec.Command("systemctl", "restart", "anon").Run(); err != nil { + fmt.Fprintf(os.Stderr, "⚠️ Failed to restart Anon service: %v\n", err) + } else { + fmt.Printf(" ✓ Anon service restarted\n") + } } }