fix(hub): restart beszel-hub.service after update (#2410)

restartService only looked for beszel.service, but install-hub.sh installs
the unit as beszel-hub.service, so the restart was skipped on a standard
install and the hub kept running the old binary.

Try the installer's name first and keep beszel.service as a fallback for
hand written units. Same for the OpenRC branch.
This commit is contained in:
Mario Mohar
2026-09-24 16:00:18 +02:00
committed by GitHub
parent a99fe5e997
commit fc33e62736

View File

@@ -58,36 +58,38 @@ func Update(cmd *cobra.Command, _ []string) {
func restartService() { func restartService() {
// Check if we're running as a service by looking for systemd // Check if we're running as a service by looking for systemd
if _, err := exec.LookPath("systemctl"); err == nil { if _, err := exec.LookPath("systemctl"); err == nil {
// Check if beszel service exists and is active // install-hub.sh names the unit beszel-hub.service. beszel.service is
cmd := exec.Command("systemctl", "is-active", "beszel.service") // kept as a fallback for hand written units.
if err := cmd.Run(); err == nil { for _, unit := range []string{"beszel-hub.service", "beszel.service"} {
ghupdate.ColorPrint(ghupdate.ColorYellow, "Restarting beszel service...") if err := exec.Command("systemctl", "is-active", unit).Run(); err != nil {
restartCmd := exec.Command("systemctl", "restart", "beszel.service") continue
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")
} }
reportRestart(exec.Command("systemctl", "restart", unit), "sudo systemctl restart "+unit)
return return
} }
} }
// Check for OpenRC (Alpine Linux) // Check for OpenRC (Alpine Linux)
if _, err := exec.LookPath("rc-service"); err == nil { if _, err := exec.LookPath("rc-service"); err == nil {
cmd := exec.Command("rc-service", "beszel", "status") for _, service := range []string{"beszel-hub", "beszel"} {
if err := cmd.Run(); err == nil { if err := exec.Command("rc-service", service, "status").Run(); err != nil {
ghupdate.ColorPrint(ghupdate.ColorYellow, "Restarting beszel service...") continue
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")
} }
reportRestart(exec.Command("rc-service", service, "restart"), "sudo rc-service "+service+" restart")
return return
} }
} }
ghupdate.ColorPrint(ghupdate.ColorYellow, "Service restart not attempted. If running as a service, restart manually.") 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")
}
}