From e28cbfe5ce20fc9154dc67442dfd3be15696d803 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Thu, 21 Jun 2018 13:51:57 -0600 Subject: [PATCH] Only main catches signals --- main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index a9e90b6..47f2994 100644 --- a/main.go +++ b/main.go @@ -10,7 +10,10 @@ import ( "local/natsc" "local/system/sysconf" "net/http" + "os" + "os/signal" "regexp" + "syscall" "time" ) @@ -25,7 +28,7 @@ func main() { client := &http.Client{Timeout: time.Second * 30} sub, err := natsc.NewSubscriber(config.DB) if err != nil { - exit <- true + <-exit panic(err) } defer sub.Close() @@ -43,7 +46,16 @@ func main() { }() //magnets <- "magnet:?xt=urn:btih:64b2b05f61d2b9ef3213fce9860fb45c844d77fb&dn=checkmyiptorrent&tr=http%3A%2F%2F34.204.227.31%2Fcheckmytorrentipaddress.php" + sigc := make(chan os.Signal) + signal.Notify(sigc, + syscall.SIGINT, + ) + <-sigc <-exit + select { + case <-exit: + case <-time.After(time.Second * 10): + } logger.Log("Exit received") }