From 96e0332d1602a7a49aaa5b147936e4743a1640cb Mon Sep 17 00:00:00 2001 From: dingjun Date: Tue, 16 Apr 2019 09:42:52 +0800 Subject: [PATCH] add signal handler --- main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 13fa728..e8a996d 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,10 @@ import ( "io" "io/ioutil" "net" + "os" + "os/signal" "strings" + "syscall" glog "github.com/fangdingjun/go-log" proxyproto "github.com/pires/go-proxyproto" @@ -202,5 +205,11 @@ func main() { } }(l) } - select {} + + ch := make(chan os.Signal, 2) + signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM) + select { + case s := <-ch: + glog.Printf("received signal %s, exit.", s) + } }