add signal handling boilerblate

This commit is contained in:
Jeff Becker
2017-08-27 10:48:34 -04:00
parent 0765c8b302
commit aeb33c27aa
7 changed files with 150 additions and 4 deletions

30
lib/util/signals/unix.go Normal file
View File

@ -0,0 +1,30 @@
// +build !windows
package signals
import (
"os/signal"
"syscall"
)
func init() {
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
}
func Handle() {
for {
sig, ok := <-sigChan
if !ok {
// closed channel
return
}
if sig == syscall.SIGHUP {
handleReload()
} else if sig == syscall.SIGINT || sig == syscall.SIGTERM {
handleInterrupted()
} else {
// wtf?
}
}
}