From 3e30c5916b91434155dca060503b4d68c03705f8 Mon Sep 17 00:00:00 2001 From: Ken Hibino Date: Tue, 17 Dec 2019 05:32:31 -0800 Subject: [PATCH] Trap and handle TSTP signal --- background.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/background.go b/background.go index 8cc03ea..9649a2a 100644 --- a/background.go +++ b/background.go @@ -77,8 +77,16 @@ func (bg *Background) Run(handler Handler) { // Wait for a signal to terminate. sigs := make(chan os.Signal, 1) - signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT) - <-sigs + signal.Notify(sigs, syscall.SIGTERM, syscall.SIGINT, syscall.SIGTSTP) + for { + sig := <-sigs + fmt.Printf("[DEBUG] Got %v\n", sig) // TODO: Remove this + if sig == syscall.SIGTSTP { + fmt.Println("[DEBUG] Stop processing tasks") + continue + } + break + } fmt.Println() log.Println("[INFO] Starting graceful shutdown...") }