From 587c89d9798df451d1dced957196d9491a442e2f Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Sun, 7 Mar 2021 15:25:55 +0100 Subject: [PATCH] cmd/syncthing, etc: Consistent failure restart backoff (#7439) --- cmd/syncthing/monitor.go | 13 +++++++------ etc/linux-systemd/system/syncthing@.service | 4 +++- etc/linux-systemd/user/syncthing.service | 4 +++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/syncthing/monitor.go b/cmd/syncthing/monitor.go index 829daec8e..2d7520d7b 100644 --- a/cmd/syncthing/monitor.go +++ b/cmd/syncthing/monitor.go @@ -36,8 +36,9 @@ var ( ) const ( - countRestarts = 4 - loopThreshold = 60 * time.Second + restartCounts = 4 + restartPause = 1 * time.Second + restartLoopThreshold = 60 * time.Second logFileAutoCloseDelay = 5 * time.Second logFileMaxOpenTime = time.Minute panicUploadMaxWait = 30 * time.Second @@ -84,7 +85,7 @@ func monitorMain(options serveOptions) { } args := os.Args - var restarts [countRestarts]time.Time + var restarts [restartCounts]time.Time stopSign := make(chan os.Signal, 1) signal.Notify(stopSign, os.Interrupt, sigTerm) @@ -97,8 +98,8 @@ func monitorMain(options serveOptions) { for { maybeReportPanics() - if t := time.Since(restarts[0]); t < loopThreshold { - l.Warnf("%d restarts in %v; not retrying further", countRestarts, t) + if t := time.Since(restarts[0]); t < restartLoopThreshold { + l.Warnf("%d restarts in %v; not retrying further", restartCounts, t) os.Exit(svcutil.ExitError.AsInt()) } @@ -193,7 +194,7 @@ func monitorMain(options serveOptions) { } l.Infoln("Syncthing exited:", err) - time.Sleep(1 * time.Second) + time.Sleep(restartPause) if first { // Let the next child process know that this is not the first time diff --git a/etc/linux-systemd/system/syncthing@.service b/etc/linux-systemd/system/syncthing@.service index 6d676009c..ceb86e952 100644 --- a/etc/linux-systemd/system/syncthing@.service +++ b/etc/linux-systemd/system/syncthing@.service @@ -7,7 +7,9 @@ After=network.target User=%i ExecStart=/usr/bin/syncthing serve --no-browser --no-restart --logflags=0 Restart=on-failure -RestartSec=5 +RestartSec=1 +StartLimitIntervalSec=60 +StartLimitBurst=4 SuccessExitStatus=3 4 RestartForceExitStatus=3 4 diff --git a/etc/linux-systemd/user/syncthing.service b/etc/linux-systemd/user/syncthing.service index 7ad05d95a..e28ec8b5e 100644 --- a/etc/linux-systemd/user/syncthing.service +++ b/etc/linux-systemd/user/syncthing.service @@ -5,7 +5,9 @@ Documentation=man:syncthing(1) [Service] ExecStart=/usr/bin/syncthing serve --no-browser --no-restart --logflags=0 Restart=on-failure -RestartSec=5 +RestartSec=1 +StartLimitIntervalSec=60 +StartLimitBurst=4 SuccessExitStatus=3 4 RestartForceExitStatus=3 4