From c731a99647c67aa9374e5663342b2cf83ed390cd Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 26 Mar 2019 18:15:07 -0700 Subject: [PATCH] signal: catch all termination signals by default In this commit, we modify the primary `signal` package to instead catch all signals. Before this commit, it would only catch the interrupt signal sent from the kernel. With this new commit, we'll now also catch (or attempt to catch): `SIGABRT`, `SIGTERM`, `SIGSTOP`, and `SIGQUIT`. --- signal/signal.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/signal/signal.go b/signal/signal.go index f1a5b978..c6c90395 100644 --- a/signal/signal.go +++ b/signal/signal.go @@ -8,6 +8,7 @@ package signal import ( "os" "os/signal" + "syscall" ) var ( @@ -26,7 +27,15 @@ var ( ) func init() { - signal.Notify(interruptChannel, os.Interrupt) + signalsToCatch := []os.Signal{ + os.Interrupt, + os.Kill, + syscall.SIGABRT, + syscall.SIGTERM, + syscall.SIGSTOP, + syscall.SIGQUIT, + } + signal.Notify(interruptChannel, signalsToCatch...) go mainInterruptHandler() } @@ -60,8 +69,8 @@ func mainInterruptHandler() { for { select { - case <-interruptChannel: - log.Infof("Received SIGINT (Ctrl+C).") + case signal := <-interruptChannel: + log.Infof("Received %v", signal) shutdown() case <-shutdownRequestChannel: