terminator/terminator.go

26 lines
534 B
Go
Raw Normal View History

2020-05-29 16:35:56 +02:00
package terminator /* import "udico.de/uditaren/terminator" */
import (
"os"
"os/signal"
"syscall"
)
// enable to react to
// <-terminator.Terminate
// nicely
var Terminate = make(chan struct{})
func init() {
sigs := make(chan os.Signal)
signal.Notify(sigs, os.Interrupt, os.Kill)
signal.Notify(sigs, syscall.SIGTERM)
// When notified about SIGINT, SIGTERM, or SIGKILL close the Terminator channel
// in order to notify interested parties to quit.
go func(c <-chan os.Signal) {
<-c
2020-05-29 16:37:38 +02:00
close(Terminate)
2020-05-29 16:35:56 +02:00
}(sigs)
}