mirror of
https://github.com/henrygd/beszel.git
synced 2026-09-25 09:24:19 +00:00
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:
+21
-19
@@ -58,36 +58,38 @@ func Update(cmd *cobra.Command, _ []string) {
|
||||
func restartService() {
|
||||
// Check if we're running as a service by looking for systemd
|
||||
if _, 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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user