cmd/syncthing, etc: Consistent failure restart backoff (#7439)

This commit is contained in:
Simon Frei 2021-03-07 15:25:55 +01:00 committed by GitHub
parent 310fba4c12
commit 587c89d979
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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