From 30e979d2527817eead2cd9786023aa3e247f9186 Mon Sep 17 00:00:00 2001 From: Brian Harring Date: Mon, 19 Feb 2024 11:09:25 +0100 Subject: [PATCH 1/3] Catch SIGTERM, run cleanup The previous code only ran cleanup (lock release for example) on SIGINT. For anyone running restic in a container, the signal is going to be SIGTERM which means containerized execution would leave locks behind. While this could be addressed via interposing dumb-init to translate the signal, a `kill` invocation is going to default to SIGTERM, so the same problem exists for non container users. Signed-off-by: Brian Harring --- cmd/restic/cleanup.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/restic/cleanup.go b/cmd/restic/cleanup.go index 75933fe96..d1c8ecc1a 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 @@ -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 From b41107dcaf214743b0bc6edc445a6d1882a3283c Mon Sep 17 00:00:00 2001 From: Brian Harring Date: Mon, 19 Feb 2024 11:31:48 +0100 Subject: [PATCH 2/3] Add changelog for SIGTERM bugfix. Signed-off-by: Brian Harring --- changelog/unreleased/pull-4703 | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 changelog/unreleased/pull-4703 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 From 0a65a0f94fa6d22a32e227024f34c23126b754e3 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Thu, 22 Feb 2024 22:00:42 +0100 Subject: [PATCH 3/3] update comment --- cmd/restic/cleanup.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/restic/cleanup.go b/cmd/restic/cleanup.go index d1c8ecc1a..5a6cf79e1 100644 --- a/cmd/restic/cleanup.go +++ b/cmd/restic/cleanup.go @@ -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)