Lightweight server monitoring with historical data, docker stats, and alerts.
fix(hub): restart beszel-hub.service after update (#2410)
Mario Moharfc33e6273610
diff --git a/internal/hub/update.go b/internal/hub/update.goindex 4ae990ef8..2ba106014 100644--- a/internal/hub/update.go+++ b/internal/hub/update.go@@ -58,36 +58,38 @@ func Update(cmd *cobra.Command, _ []string) {func restartService() {// Check if we're running as a service by looking for systemdif _, err := exec.LookPath("systemctl"); err == nil {- // Check if beszel service exists and is active- cmd := exec.Command("systemctl", "is-active", "beszel.service")- if err := cmd.Run(); err == nil {- ghupdate.ColorPrint(ghupdate.ColorYellow, "Restarting beszel service...")- restartCmd := exec.Command("systemctl", "restart", "beszel.service")- if err := restartCmd.Run(); err != nil {- ghupdate.ColorPrintf(ghupdate.ColorYellow, "Warning: Failed to restart service: %v\n", err)- ghupdate.ColorPrint(ghupdate.ColorYellow, "Please restart the service manually: sudo systemctl restart beszel")- } else {- ghupdate.ColorPrint(ghupdate.ColorGreen, "Service restarted successfully")+ // install-hub.sh names the unit beszel-hub.service. beszel.service is+ // kept as a fallback for hand written units.+ for _, unit := range []string{"beszel-hub.service", "beszel.service"} {+ if err := exec.Command("systemctl", "is-active", unit).Run(); err != nil {+ continue}+ reportRestart(exec.Command("systemctl", "restart", unit), "sudo systemctl restart "+unit)return}}// Check for OpenRC (Alpine Linux)if _, err := exec.LookPath("rc-service"); err == nil {- cmd := exec.Command("rc-service", "beszel", "status")- if err := cmd.Run(); err == nil {- ghupdate.ColorPrint(ghupdate.ColorYellow, "Restarting beszel service...")- restartCmd := exec.Command("rc-service", "beszel", "restart")- if err := restartCmd.Run(); err != nil {- ghupdate.ColorPrintf(ghupdate.ColorYellow, "Warning: Failed to restart service: %v\n", err)- ghupdate.ColorPrint(ghupdate.ColorYellow, "Please restart the service manually: sudo rc-service beszel restart")- } else {- ghupdate.ColorPrint(ghupdate.ColorGreen, "Service restarted successfully")+ for _, service := range []string{"beszel-hub", "beszel"} {+ if err := exec.Command("rc-service", service, "status").Run(); err != nil {+ continue}+ reportRestart(exec.Command("rc-service", service, "restart"), "sudo rc-service "+service+" restart")return}}ghupdate.ColorPrint(ghupdate.ColorYellow, "Service restart not attempted. If running as a service, restart manually.")}++// reportRestart runs the restart command and prints the result.+func reportRestart(cmd *exec.Cmd, manualCommand string) {+ ghupdate.ColorPrint(ghupdate.ColorYellow, "Restarting beszel service...")+ if err := cmd.Run(); err != nil {+ ghupdate.ColorPrintf(ghupdate.ColorYellow, "Warning: Failed to restart service: %v\n", err)+ ghupdate.ColorPrint(ghupdate.ColorYellow, "Please restart the service manually: "+manualCommand)+ } else {+ ghupdate.ColorPrint(ghupdate.ColorGreen, "Service restarted successfully")+ }+}