Merge pull request #798 from miekg/hup-signal-handing

Start HUP signal handler earlier
This commit is contained in:
Julius Volz 2015-06-12 15:46:43 +02:00
commit 6247bd5a5a

21
main.go
View file

@ -247,6 +247,19 @@ func (p *prometheus) reloadConfig() bool {
// down. The method installs an interrupt handler, allowing to trigger a
// shutdown by sending SIGTERM to the process.
func (p *prometheus) Serve() {
// Wait for reload or termination signals. Start the handler for SIGHUP as
// early as possible, but ignore it until we are ready to handle reloading
// our config.
hup := make(chan os.Signal)
hupReady := make(chan bool)
signal.Notify(hup, syscall.SIGHUP)
go func() {
<-hupReady
for range hup {
p.reloadConfig()
}
}()
// Start all components.
if err := p.storage.Start(); err != nil {
log.Errorln("Error opening memory series storage:", err)
@ -280,13 +293,7 @@ func (p *prometheus) Serve() {
go p.webService.Run()
// Wait for reload or termination signals.
hup := make(chan os.Signal)
signal.Notify(hup, syscall.SIGHUP)
go func() {
for range hup {
p.reloadConfig()
}
}()
close(hupReady) // Unblock SIGHUP handler.
term := make(chan os.Signal)
signal.Notify(term, os.Interrupt, syscall.SIGTERM)