From a5e3317e28cfef2718540166cac509696c4368d9 Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Sat, 13 Sep 2014 15:25:39 +0100 Subject: [PATCH] Restart monitor as part of the upgrade process (fixes #682) --- cmd/syncthing/gui.go | 4 +++- cmd/syncthing/main.go | 1 + cmd/syncthing/monitor.go | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index e0afc7d3d..a3c015337 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -541,7 +541,9 @@ func restPostUpgrade(w http.ResponseWriter, r *http.Request) { return } - restPostRestart(w, r) + flushResponse(`{"ok": "restarting"}`, w) + l.Infoln("Upgrading") + stop <- exitUpgrading } } diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index da577afd2..b980cbf7d 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -56,6 +56,7 @@ const ( exitError = 1 exitNoUpgradeAvailable = 2 exitRestarting = 3 + exitUpgrading = 4 ) var l = logger.DefaultLogger diff --git a/cmd/syncthing/monitor.go b/cmd/syncthing/monitor.go index ad8abddca..43582c989 100644 --- a/cmd/syncthing/monitor.go +++ b/cmd/syncthing/monitor.go @@ -91,6 +91,18 @@ func monitorMain() { if err == nil { // Successfull exit indicates an intentional shutdown return + } else if exiterr, ok := err.(*exec.ExitError); ok { + if status, ok := exiterr.Sys().(syscall.WaitStatus); ok { + switch status.ExitStatus() { + case exitUpgrading: + // Restart the monitor process to release the .old + // binary as part of the upgrade process. + l.Infoln("Restarting monitor...") + os.Setenv("STNORESTART", "") + exec.Command(args[0], args[1:]...).Start() + return + } + } } }