From 9ab7cab19ec8bc7983bc0b5bd685775e354ff427 Mon Sep 17 00:00:00 2001 From: Mildred Ki'Lya Date: Fri, 2 Dec 2016 09:55:51 +0100 Subject: [PATCH] Gracefully stops on SIGTERM --- commands.go | 2 +- signal_unix.go | 10 ++++++++++ signal_windows.go | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 signal_unix.go create mode 100644 signal_windows.go diff --git a/commands.go b/commands.go index dbffe9b7a..b7492db35 100644 --- a/commands.go +++ b/commands.go @@ -223,7 +223,7 @@ func makeShutdownCh() <-chan struct{} { resultCh := make(chan struct{}) signalCh := make(chan os.Signal, 4) - signal.Notify(signalCh, os.Interrupt) + signal.Notify(signalCh, interruptSignals...) go func() { for { <-signalCh diff --git a/signal_unix.go b/signal_unix.go new file mode 100644 index 000000000..9f22ecf10 --- /dev/null +++ b/signal_unix.go @@ -0,0 +1,10 @@ +// +build !windows + +package main + +import ( + "os" + "syscall" +) + +var interruptSignals []os.Signal = []os.Signal{os.Interrupt, syscall.SIGTERM} diff --git a/signal_windows.go b/signal_windows.go new file mode 100644 index 000000000..885df4ee4 --- /dev/null +++ b/signal_windows.go @@ -0,0 +1,9 @@ +// +build windows + +package main + +import ( + "os" +) + +var interruptSignals []os.Signal = []os.Signal{os.Interrupt}