diff --git a/changelog/unreleased/pull-4703 b/changelog/unreleased/pull-4703 new file mode 100644 index 000000000..4df3385a0 --- /dev/null +++ b/changelog/unreleased/pull-4703 @@ -0,0 +1,9 @@ +Bugfix: Shutdown cleanly when SIGTERM is received + +Prior, if restic received SIGTERM it'd just immediately terminate skipping +cleanup- resulting in potential issues like stale locks being left behind. + +This primarily effected containerized restic invocations- they use SIGTERM- +but this could be triggered via a simple `killall restic` in addition. + +https://github.com/restic/restic/pull/4703 diff --git a/cmd/restic/cleanup.go b/cmd/restic/cleanup.go index 75933fe96..5a6cf79e1 100644 --- a/cmd/restic/cleanup.go +++ b/cmd/restic/cleanup.go @@ -19,7 +19,7 @@ var cleanupHandlers struct { func init() { cleanupHandlers.ch = make(chan os.Signal, 1) go CleanupHandler(cleanupHandlers.ch) - signal.Notify(cleanupHandlers.ch, syscall.SIGINT) + signal.Notify(cleanupHandlers.ch, syscall.SIGINT, syscall.SIGTERM) } // AddCleanupHandler adds the function f to the list of cleanup handlers so @@ -56,7 +56,7 @@ func RunCleanupHandlers(code int) int { return code } -// CleanupHandler handles the SIGINT signals. +// CleanupHandler handles the SIGINT and SIGTERM signals. func CleanupHandler(c <-chan os.Signal) { for s := range c { debug.Log("signal %v received, cleaning up", s) @@ -70,7 +70,7 @@ func CleanupHandler(c <-chan os.Signal) { code := 0 - if s == syscall.SIGINT { + if s == syscall.SIGINT || s == syscall.SIGTERM { code = 130 } else { code = 1