|
@@ -68,10 +68,7 @@ const (
|
|
|
maxSystemLog = 250
|
|
maxSystemLog = 250
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-var (
|
|
|
|
|
- myID protocol.DeviceID
|
|
|
|
|
- stop = make(chan int)
|
|
|
|
|
-)
|
|
|
|
|
|
|
+var myID protocol.DeviceID
|
|
|
|
|
|
|
|
const (
|
|
const (
|
|
|
usage = "syncthing [options]"
|
|
usage = "syncthing [options]"
|
|
@@ -264,6 +261,32 @@ func parseCommandLineOptions() RuntimeOptions {
|
|
|
return options
|
|
return options
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+type exiter struct {
|
|
|
|
|
+ stop chan int
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (e *exiter) Restart() {
|
|
|
|
|
+ l.Infoln("Restarting")
|
|
|
|
|
+ e.stop <- exitRestarting
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (e *exiter) Shutdown() {
|
|
|
|
|
+ l.Infoln("Shutting down")
|
|
|
|
|
+ e.stop <- exitSuccess
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func (e *exiter) ExitUpgrading() {
|
|
|
|
|
+ l.Infoln("Shutting down after upgrade")
|
|
|
|
|
+ e.stop <- exitUpgrading
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// waitForExit must be called synchronously.
|
|
|
|
|
+func (e *exiter) waitForExit() int {
|
|
|
|
|
+ return <-e.stop
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+var exit = exiter{make(chan int)}
|
|
|
|
|
+
|
|
|
func main() {
|
|
func main() {
|
|
|
options := parseCommandLineOptions()
|
|
options := parseCommandLineOptions()
|
|
|
l.SetFlags(options.logFlags)
|
|
l.SetFlags(options.logFlags)
|
|
@@ -858,7 +881,7 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- code := <-stop
|
|
|
|
|
|
|
+ code := exit.waitForExit()
|
|
|
|
|
|
|
|
mainService.Stop()
|
|
mainService.Stop()
|
|
|
|
|
|
|
@@ -879,7 +902,7 @@ func setupSignalHandling() {
|
|
|
signal.Notify(restartSign, sigHup)
|
|
signal.Notify(restartSign, sigHup)
|
|
|
go func() {
|
|
go func() {
|
|
|
<-restartSign
|
|
<-restartSign
|
|
|
- stop <- exitRestarting
|
|
|
|
|
|
|
+ exit.Restart()
|
|
|
}()
|
|
}()
|
|
|
|
|
|
|
|
// Exit with "success" code (no restart) on INT/TERM
|
|
// Exit with "success" code (no restart) on INT/TERM
|
|
@@ -889,7 +912,7 @@ func setupSignalHandling() {
|
|
|
signal.Notify(stopSign, os.Interrupt, sigTerm)
|
|
signal.Notify(stopSign, os.Interrupt, sigTerm)
|
|
|
go func() {
|
|
go func() {
|
|
|
<-stopSign
|
|
<-stopSign
|
|
|
- stop <- exitSuccess
|
|
|
|
|
|
|
+ exit.Shutdown()
|
|
|
}()
|
|
}()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1034,16 +1057,6 @@ func resetDB() error {
|
|
|
return os.RemoveAll(locations.Get(locations.Database))
|
|
return os.RemoveAll(locations.Get(locations.Database))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func restart() {
|
|
|
|
|
- l.Infoln("Restarting")
|
|
|
|
|
- stop <- exitRestarting
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func shutdown() {
|
|
|
|
|
- l.Infoln("Shutting down")
|
|
|
|
|
- stop <- exitSuccess
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
func ensureDir(dir string, mode fs.FileMode) {
|
|
func ensureDir(dir string, mode fs.FileMode) {
|
|
|
fs := fs.NewFilesystem(fs.FilesystemTypeBasic, dir)
|
|
fs := fs.NewFilesystem(fs.FilesystemTypeBasic, dir)
|
|
|
err := fs.MkdirAll(".", mode)
|
|
err := fs.MkdirAll(".", mode)
|
|
@@ -1079,7 +1092,7 @@ func standbyMonitor() {
|
|
|
// things a moment to stabilize.
|
|
// things a moment to stabilize.
|
|
|
time.Sleep(restartDelay)
|
|
time.Sleep(restartDelay)
|
|
|
|
|
|
|
|
- restart()
|
|
|
|
|
|
|
+ exit.Restart()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
now = time.Now()
|
|
now = time.Now()
|
|
@@ -1137,7 +1150,7 @@ func autoUpgrade(cfg *config.Wrapper) {
|
|
|
events.Default.Unsubscribe(sub)
|
|
events.Default.Unsubscribe(sub)
|
|
|
l.Warnf("Automatically upgraded to version %q. Restarting in 1 minute.", rel.Tag)
|
|
l.Warnf("Automatically upgraded to version %q. Restarting in 1 minute.", rel.Tag)
|
|
|
time.Sleep(time.Minute)
|
|
time.Sleep(time.Minute)
|
|
|
- stop <- exitUpgrading
|
|
|
|
|
|
|
+ exit.ExitUpgrading()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|