lib/procutil: add NewSighupChan function, which returns a channel, which is triggered on every SIGHUP

This commit is contained in:
Aliaksandr Valialkin 2020-05-05 09:27:38 +03:00
parent 1aea001532
commit 7b5ef63384
2 changed files with 10 additions and 6 deletions

View File

@ -16,8 +16,8 @@ import (
// since this signal is frequently used for config reloading. // since this signal is frequently used for config reloading.
func WaitForSigterm() os.Signal { func WaitForSigterm() os.Signal {
ch := make(chan os.Signal, 1) ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
for { for {
signal.Notify(ch, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
sig := <-ch sig := <-ch
if sig == syscall.SIGHUP { if sig == syscall.SIGHUP {
// Prevent from the program stop on SIGHUP // Prevent from the program stop on SIGHUP
@ -33,3 +33,10 @@ func SelfSIGHUP() {
logger.Panicf("FATAL: cannot send SIGHUP to itself: %s", err) 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
}

View File

@ -4,13 +4,11 @@ import (
"bytes" "bytes"
"flag" "flag"
"fmt" "fmt"
"os"
"os/signal"
"sync" "sync"
"syscall"
"time" "time"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/procutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal" "github.com/VictoriaMetrics/VictoriaMetrics/lib/prompbmarshal"
"github.com/VictoriaMetrics/metrics" "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("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() }) scs.add("gce_sd_configs", *gceSDCheckInterval, func(cfg *Config, swsPrev []ScrapeWork) []ScrapeWork { return cfg.getGCESDScrapeWork() })
sighupCh := make(chan os.Signal, 1) sighupCh := procutil.NewSighupChan()
signal.Notify(sighupCh, syscall.SIGHUP)
var tickerCh <-chan time.Time var tickerCh <-chan time.Time
if *configCheckInterval > 0 { if *configCheckInterval > 0 {