geck-go/daemon/wait.go

30 lines
609 B
Go

package daemon
import (
"log/slog"
"os"
"os/signal"
"syscall"
)
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) os.Signal {
ch := make(chan os.Signal, 1)
signal.Notify(ch, sig...)
s := <-ch
slog.Debug("Signal caught", "signal", s.String())
return s
}
// WaitForSignalsDefault waits until one of SIGINT, SIGQUIT or SIGTERM is received.
func WaitForSignalsDefault() {
WaitForSignal(Interrupt, Quit, Terminate)
}