Browse Source

Merge branch 'pr/683'

* pr/683:
  Restart monitor as part of the upgrade process (fixes #682)
Jakob Borg 11 years ago
parent
commit
517b7a14b4
3 changed files with 16 additions and 1 deletions
  1. 3 1
      cmd/syncthing/gui.go
  2. 1 0
      cmd/syncthing/main.go
  3. 12 0
      cmd/syncthing/monitor.go

+ 3 - 1
cmd/syncthing/gui.go

@@ -531,7 +531,9 @@ func restPostUpgrade(w http.ResponseWriter, r *http.Request) {
 			return
 		}
 
-		restPostRestart(w, r)
+		flushResponse(`{"ok": "restarting"}`, w)
+		l.Infoln("Upgrading")
+		stop <- exitUpgrading
 	}
 }
 

+ 1 - 0
cmd/syncthing/main.go

@@ -56,6 +56,7 @@ const (
 	exitError              = 1
 	exitNoUpgradeAvailable = 2
 	exitRestarting         = 3
+	exitUpgrading          = 4
 )
 
 var l = logger.DefaultLogger

+ 12 - 0
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
+					}
+				}
 			}
 		}