Start HUP signal handler earlier

When prometheus starts up and is recovering its state it will not handle
SIGHUPs. If it receives those during this phase it will exit. The change
here makes prometheus ignore SIGHUPs until it is ready to handle them.

Note this is only done for SIGHUP because that signal is used for
trigger a config reload and a such something could already be sending
these signals as part of a config update.
This commit is contained in:
Miek Gieben 2015-06-12 13:48:06 +01:00
parent 0542733964
commit d8651302fc

22
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)
block := make(chan bool)
signal.Notify(hup, syscall.SIGHUP)
go func() {
<-block
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,8 @@ 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()
}
}()
block <- true // Unblock SIGHUP handler.
close(block)
term := make(chan os.Signal)
signal.Notify(term, os.Interrupt, syscall.SIGTERM)