From d8651302fcec02bc46a648a09aba610189629604 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Fri, 12 Jun 2015 13:48:06 +0100 Subject: [PATCH] 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. --- main.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 3555d8cc8..079c23de1 100644 --- a/main.go +++ b/main.go @@ -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)