Implement graceful shutdown

This commit is contained in:
Fabian Reinartz 2015-09-29 11:42:29 +02:00
parent 3b401c413b
commit 3d9e7286de
1 changed files with 9 additions and 1 deletions

10
main.go
View File

@ -16,6 +16,9 @@ package main
import (
"flag"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/prometheus/common/log"
"github.com/prometheus/common/route"
@ -73,5 +76,10 @@ func main() {
NewAPI(router.WithPrefix("/api"), alerts, silences)
http.ListenAndServe(":9091", router)
go http.ListenAndServe(":9091", router)
term := make(chan os.Signal)
signal.Notify(term, os.Interrupt, syscall.SIGTERM)
<-term
log.Warn("Received SIGTERM, exiting gracefully...")
}