Merge pull request #4703 from ferringb/master

Catch SIGTERM, run cleanup
This commit is contained in:
Michael Eischer 2024-02-22 21:06:29 +00:00 committed by GitHub
commit c6311c1e32
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View file

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

View file

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