Skip to content

Commit

Permalink
signal: catch all termination signals by default
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
Roasbeef committed Mar 27, 2019
1 parent ec70965 commit c731a99
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions signal/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package signal
import (
"os"
"os/signal"
"syscall"
)

var (
Expand All @@ -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()
}

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit c731a99

Please sign in to comment.