VictoriaMetrics/lib/procutil/signal.go

36 lines
813 B
Go
Raw Normal View History

2019-05-22 21:16:55 +00:00
package procutil
import (
"os"
"os/signal"
"syscall"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
2019-05-22 21:16:55 +00:00
)
// WaitForSigterm waits for either SIGTERM or SIGINT
2019-05-22 21:16:55 +00:00
//
// Returns the caught signal.
//
// It also prevent from program termination on SIGHUP signal,
// since this signal is frequently used for config reloading.
2019-05-22 21:16:55 +00:00
func WaitForSigterm() os.Signal {
ch := make(chan os.Signal, 1)
for {
signal.Notify(ch, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
sig := <-ch
if sig == syscall.SIGHUP {
// Prevent from the program stop on SIGHUP
continue
}
return sig
}
2019-05-22 21:16:55 +00:00
}
// SelfSIGHUP sends SIGHUP signal to the current process.
func SelfSIGHUP() {
if err := syscall.Kill(syscall.Getpid(), syscall.SIGHUP); err != nil {
logger.Panicf("FATAL: cannot send SIGHUP to itself: %s", err)
}
}