Fixup: make signal handlers a bit simpler.
No need to spawn a goroutine, nor wait for a channel. Let's just put everything in a single select call. Signed-off-by: Xavier Nicollet <xnicollet@gmail.com>
This commit is contained in:
parent
1045dc0f21
commit
7dd34c6b4c
|
@ -548,14 +548,11 @@ func run() int {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
hup = make(chan os.Signal, 1)
|
hup = make(chan os.Signal, 1)
|
||||||
hupReady = make(chan bool)
|
|
||||||
term = make(chan os.Signal, 1)
|
term = make(chan os.Signal, 1)
|
||||||
)
|
)
|
||||||
signal.Notify(hup, syscall.SIGHUP)
|
signal.Notify(hup, syscall.SIGHUP)
|
||||||
signal.Notify(term, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(term, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
||||||
go func() {
|
|
||||||
<-hupReady
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-hup:
|
case <-hup:
|
||||||
|
@ -563,15 +560,6 @@ func run() int {
|
||||||
_ = configCoordinator.Reload()
|
_ = configCoordinator.Reload()
|
||||||
case errc := <-webReload:
|
case errc := <-webReload:
|
||||||
errc <- configCoordinator.Reload()
|
errc <- configCoordinator.Reload()
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Wait for reload or termination signals.
|
|
||||||
close(hupReady) // Unblock SIGHUP handler.
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-term:
|
case <-term:
|
||||||
level.Info(logger).Log("msg", "Received SIGTERM, exiting gracefully...")
|
level.Info(logger).Log("msg", "Received SIGTERM, exiting gracefully...")
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Reference in New Issue