mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-25 08:41:00 +00:00
use a quit channel and log exit messages
Signed-off-by: glightfoot <glightfoot@rsglab.com>
This commit is contained in:
parent
6a9749cd42
commit
ee3b81b864
1 changed files with 12 additions and 5 deletions
17
main.go
17
main.go
|
@ -478,8 +478,7 @@ func main() {
|
||||||
</html>`))
|
</html>`))
|
||||||
})
|
})
|
||||||
|
|
||||||
signals := make(chan os.Signal, 1)
|
quitChan := make(chan struct{}, 1)
|
||||||
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
|
|
||||||
|
|
||||||
if *enableLifecycle {
|
if *enableLifecycle {
|
||||||
mux.HandleFunc("/-/reload", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/-/reload", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -496,8 +495,7 @@ func main() {
|
||||||
mux.HandleFunc("/-/quit", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/-/quit", func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method == http.MethodPut || r.Method == http.MethodPost {
|
if r.Method == http.MethodPut || r.Method == http.MethodPost {
|
||||||
fmt.Fprintf(w, "Requesting termination... Goodbye!")
|
fmt.Fprintf(w, "Requesting termination... Goodbye!")
|
||||||
level.Info(logger).Log("msg", "Received lifecycle api quit, exiting")
|
quitChan <- struct{}{}
|
||||||
signals <- os.Kill
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -523,5 +521,14 @@ func main() {
|
||||||
go sighupConfigReloader(*mappingConfig, mapper, *cacheSize, logger, cacheOption)
|
go sighupConfigReloader(*mappingConfig, mapper, *cacheSize, logger, cacheOption)
|
||||||
go exporter.Listen(events)
|
go exporter.Listen(events)
|
||||||
|
|
||||||
<-signals
|
signals := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
||||||
|
// quit if we get a message on either channel
|
||||||
|
select {
|
||||||
|
case sig := <-signals:
|
||||||
|
level.Info(logger).Log("msg", "Received os signal, exiting", "signal", sig.String())
|
||||||
|
case <-quitChan:
|
||||||
|
level.Info(logger).Log("msg", "Received lifecycle api quit, exiting")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue