MCPcopy Create free account
hub / github.com/cronitorio/cronitor-cli / performUpdateWithRestart

Function performUpdateWithRestart

cmd/dash.go:3022–3060  ·  view source on GitHub ↗

performUpdateWithRestart performs the update and handles the restart

(status *UpdateStatus, sendProgress func(string))

Source from the content-addressed store, hash-verified

3020
3021// performUpdateWithRestart performs the update and handles the restart
3022func performUpdateWithRestart(status *UpdateStatus, sendProgress func(string)) error {
3023 sendProgress("Downloading new version...")
3024
3025 // Perform the update (download and replace executable)
3026 if err := performUpdate(status); err != nil {
3027 return fmt.Errorf("failed to download update: %v", err)
3028 }
3029
3030 sendProgress("Update downloaded successfully. Restarting server...")
3031
3032 // Give the UI a moment to receive the message
3033 time.Sleep(1 * time.Second)
3034
3035 // Check if we're running under systemd
3036 if isRunningUnderSystemd() {
3037 sendProgress("Detected systemd service, requesting service restart...")
3038
3039 // When running under systemd, we should let systemd handle the restart
3040 // Signal systemd to restart the service
3041 if err := requestSystemdRestart(); err != nil {
3042 // If systemd restart fails, fall back to manual restart
3043 log(fmt.Sprintf("Failed to request systemd restart, falling back to manual restart: %v", err))
3044 return performManualRestart(sendProgress)
3045 }
3046
3047 sendProgress("Update complete! Service restarting via systemd...")
3048
3049 // Give a brief moment for the response to be sent, then exit gracefully
3050 go func() {
3051 time.Sleep(500 * time.Millisecond)
3052 os.Exit(0)
3053 }()
3054
3055 return nil
3056 }
3057
3058 // For non-systemd environments, use manual restart
3059 return performManualRestart(sendProgress)
3060}
3061
3062// isRunningUnderSystemd checks if the current process is running under systemd
3063func isRunningUnderSystemd() bool {

Callers 1

handleUpdatePerformFunction · 0.85

Calls 5

performUpdateFunction · 0.85
isRunningUnderSystemdFunction · 0.85
requestSystemdRestartFunction · 0.85
logFunction · 0.85
performManualRestartFunction · 0.85

Tested by

no test coverage detected