Skip to content

Commit

Permalink
Merge pull request #4703 from ferringb/master
Browse files Browse the repository at this point in the history
Catch SIGTERM, run cleanup
  • Loading branch information
MichaelEischer committed Feb 22, 2024
2 parents cfbeb2c + 0a65a0f commit c6311c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions changelog/unreleased/pull-4703
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions cmd/restic/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit c6311c1

Please sign in to comment.