Skip to content

Commit

Permalink
added graceful shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrichardsmith committed Sep 8, 2018
1 parent f723773 commit a7a46d8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package main

import (
"context"
"flag"
"net/http"
"os"
"os/signal"

"github.com/jasonrichardsmith/sentry/config"
_ "github.com/jasonrichardsmith/sentry/healthz"
Expand Down Expand Up @@ -34,6 +37,18 @@ func main() {
log.Info(config.DefaultConfig)
s := mux.New(config.DefaultConfig)
var ss *http.Server

idleConnsClosed := make(chan struct{})
go func() {
sigint := make(chan os.Signal, 1)
signal.Notify(sigint, os.Interrupt)
<-sigint
if err := ss.Shutdown(context.Background()); err != nil {
log.Printf("Sentry server Shutdown: %v", err)
}
close(idleConnsClosed)
}()

if dev {
log.Info("Serving Sentry without TLS")
ss = sentry.NewSentryServerNoSSL(s)
Expand All @@ -46,4 +61,5 @@ func main() {
}
log.Fatal(ss.ListenAndServeTLS("", ""))
}
<-idleConnsClosed
}

0 comments on commit a7a46d8

Please sign in to comment.