mirror of
https://github.com/fankes/beszel.git
synced 2025-10-20 02:09:28 +08:00
[Chore] Improve auto update mechanism (#1009)
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"beszel"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/blang/semver"
|
||||
@@ -54,4 +55,45 @@ func Update(_ *cobra.Command, _ []string) {
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("Successfully updated to %s\n\n%s\n", latest.Version, strings.TrimSpace(latest.ReleaseNotes))
|
||||
|
||||
// Try to restart the service if it's running
|
||||
restartService()
|
||||
}
|
||||
|
||||
// restartService attempts to restart the beszel service
|
||||
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 {
|
||||
fmt.Println("Restarting beszel service...")
|
||||
restartCmd := exec.Command("systemctl", "restart", "beszel.service")
|
||||
if err := restartCmd.Run(); err != nil {
|
||||
fmt.Printf("Warning: Failed to restart service: %v\n", err)
|
||||
fmt.Println("Please restart the service manually: sudo systemctl restart beszel")
|
||||
} else {
|
||||
fmt.Println("Service restarted successfully")
|
||||
}
|
||||
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 {
|
||||
fmt.Println("Restarting beszel service...")
|
||||
restartCmd := exec.Command("rc-service", "beszel", "restart")
|
||||
if err := restartCmd.Run(); err != nil {
|
||||
fmt.Printf("Warning: Failed to restart service: %v\n", err)
|
||||
fmt.Println("Please restart the service manually: sudo rc-service beszel restart")
|
||||
} else {
|
||||
fmt.Println("Service restarted successfully")
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("Note: Service restart not attempted. If running as a service, restart manually.")
|
||||
}
|
||||
|
Reference in New Issue
Block a user