mirror of
https://github.com/wearepixel/pulsewise-collector.git
synced 2026-11-14 22:12:01 +00:00
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:
@@ -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}
|
||||||
|
|||||||
Reference in New Issue
Block a user