From f04444c21088cb455545cfd7e6eb50963301ccda Mon Sep 17 00:00:00 2001 From: dingjun Date: Sat, 13 Apr 2019 12:06:20 +0800 Subject: [PATCH] add signal handle --- main.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 72c1cfb..bc30cea 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,8 @@ import ( "flag" "fmt" "os" + "os/signal" + "syscall" "github.com/fangdingjun/go-log" ) @@ -53,6 +55,11 @@ func main() { log.Debugf("%+v", cfg) makeServers(cfg) - - select {} + ch := make(chan os.Signal, 2) + signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM) + select { + case s := <-ch: + log.Errorf("received signal %s, exit...", s) + } + log.Println("exit.") }