From f9752ffcc33f2d8d943b298a02ad8b18b27db8ed Mon Sep 17 00:00:00 2001 From: Victor Vrantchan Date: Fri, 17 Mar 2017 20:13:42 +0000 Subject: [PATCH] graceful --- serve.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/serve.go b/serve.go index eb4fb015..809627a1 100644 --- a/serve.go +++ b/serve.go @@ -8,7 +8,6 @@ import ( "encoding/asn1" "encoding/pem" "flag" - "fmt" "io/ioutil" stdlog "log" "net/http" @@ -147,9 +146,11 @@ func serve(args []string) error { errs := make(chan error, 2) go func() { - c := make(chan os.Signal) - signal.Notify(c, syscall.SIGINT) - errs <- fmt.Errorf("%s", <-c) + sig := make(chan os.Signal) + signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM) + <-sig // block on signal then gracefully shutdown. + ctx, _ := context.WithTimeout(context.Background(), 30*time.Second) + errs <- srv.Shutdown(ctx) }() go func() {