diff --git a/lib/procutil/signal.go b/lib/procutil/signal.go index c4483ab1f..ade5acd2b 100644 --- a/lib/procutil/signal.go +++ b/lib/procutil/signal.go @@ -16,8 +16,8 @@ import ( // since this signal is frequently used for config reloading. func WaitForSigterm() os.Signal { ch := make(chan os.Signal, 1) + signal.Notify(ch, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP) for { - signal.Notify(ch, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP) sig := <-ch if sig == syscall.SIGHUP { // Prevent from the program stop on SIGHUP @@ -33,3 +33,10 @@ func SelfSIGHUP() { logger.Panicf("FATAL: cannot send SIGHUP to itself: %s", err) } } + +// NewSighupChan returns a channel, which is triggered on every SIGHUP. +func NewSighupChan() <-chan os.Signal { + ch := make(chan os.Signal, 1) + signal.Notify(ch, syscall.SIGHUP) + return ch +} diff --git a/lib/promscrape/scraper.go b/lib/promscrape/scraper.go index c93b9d813..8d6722631 100644 --- a/lib/promscrape/scraper.go +++ b/lib/promscrape/scraper.go @@ -4,13 +4,11 @@ import ( "bytes" "flag" "fmt" - "os" - "os/signal" "sync" - "syscall" "time" "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" + "github.com/VictoriaMetrics/VictoriaMetrics/lib/procutil" "github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal" "github.com/VictoriaMetrics/metrics" ) @@ -79,8 +77,7 @@ func runScraper(configFile string, pushData func(wr *prompbmarshal.WriteRequest) scs.add("ec2_sd_configs", *ec2SDCheckInterval, func(cfg *Config, swsPrev []ScrapeWork) []ScrapeWork { return cfg.getEC2SDScrapeWork() }) scs.add("gce_sd_configs", *gceSDCheckInterval, func(cfg *Config, swsPrev []ScrapeWork) []ScrapeWork { return cfg.getGCESDScrapeWork() }) - sighupCh := make(chan os.Signal, 1) - signal.Notify(sighupCh, syscall.SIGHUP) + sighupCh := procutil.NewSighupChan() var tickerCh <-chan time.Time if *configCheckInterval > 0 {