geck-go/daemon/wait.go
2021-12-02 09:16:01 +01:00

30 lines
620 B
Go

package daemon
import (
"os"
"os/signal"
"syscall"
"github.com/rs/zerolog/log"
)
var (
Interrupt = os.Interrupt
Quit os.Signal = syscall.SIGQUIT
Terminate os.Signal = syscall.SIGTERM
)
// WaitForSignal waits until one of the specified signals are received.
func WaitForSignal(sig ...os.Signal) {
ch := make(chan os.Signal, 1)
signal.Notify(ch, sig...)
s := <-ch
log.Debug().
Str("signal", s.String()).
Msg("Signal caught")
}
// WaitForDefaultSignals waits until one of SIGINT, SIGQUIT or SIGTERM is received.
func WaitForDefaultSignals() {
WaitForSignal(Interrupt, Quit, Terminate)
}