fix: restart service after update instead of re-execing

Both manual 'update' command and auto-updater now restart via
systemctl/launchctl after replacing the binary, so the service
manager picks up the new version cleanly. Previously the running
daemon kept executing the old binary from memory.
This commit is contained in:
Joel Male
2026-02-25 15:39:57 +10:00
parent bd63686312
commit f3f37fa372
+33 -1
View File
@@ -295,6 +295,31 @@ func runUpdateCommand() {
fmt.Printf("%sDone.%s\n", ansiGreen, ansiReset) fmt.Printf("%sDone.%s\n", ansiGreen, ansiReset)
fmt.Printf(" Successfully updated to %sv%s%s.\n\n", ansiCyan, latest, ansiReset) fmt.Printf(" Successfully updated to %sv%s%s.\n\n", ansiCyan, latest, ansiReset)
restartService()
}
func restartService() {
fmt.Printf(" %sRestarting service...%s ", ansiDim, ansiReset)
var cmd *exec.Cmd
switch runtime.GOOS {
case "linux":
cmd = exec.Command("systemctl", "restart", systemdUnit)
case "darwin":
cmd = exec.Command("launchctl", "kickstart", "-k", "system/"+launchdLabel)
default:
fmt.Printf("%snot supported on this platform%s\n\n", ansiDim, ansiReset)
return
}
if err := cmd.Run(); err != nil {
fmt.Printf("%sfailed%s (%v)\n", ansiRed, ansiReset, err)
fmt.Printf(" %sRestart manually: systemctl restart %s%s\n\n", ansiDim, systemdUnit, ansiReset)
return
}
fmt.Printf("%sdone%s\n\n", ansiGreen, ansiReset)
} }
func runDumpCommand() { func runDumpCommand() {
@@ -579,9 +604,16 @@ func checkAndUpdate(config *Config) {
return return
} }
log.Printf("Update successful. Restarting...") log.Printf("Update successful. Restarting service...")
switch runtime.GOOS {
case "linux":
exec.Command("systemctl", "restart", systemdUnit).Run()
case "darwin":
exec.Command("launchctl", "kickstart", "-k", "system/"+launchdLabel).Run()
default:
execSelf() execSelf()
} }
}
func fetchLatestVersion() (string, error) { func fetchLatestVersion() (string, error) {
client := &http.Client{Timeout: 10 * time.Second} client := &http.Client{Timeout: 10 * time.Second}