From 45d94a07a10cdac51d0ec346fe720354a426d96f Mon Sep 17 00:00:00 2001 From: uditaren Date: Fri, 29 May 2020 16:35:56 +0200 Subject: [PATCH] Initial checkin --- terminator.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 terminator.go diff --git a/terminator.go b/terminator.go new file mode 100644 index 0000000..dde3791 --- /dev/null +++ b/terminator.go @@ -0,0 +1,25 @@ +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 + close(Terminator) + }(sigs) +}