forked from TrueCloudLab/restic
Merge pull request #4703 from ferringb/master
Catch SIGTERM, run cleanup
This commit is contained in:
commit
c6311c1e32
2 changed files with 12 additions and 3 deletions
9
changelog/unreleased/pull-4703
Normal file
9
changelog/unreleased/pull-4703
Normal 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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue