add signal handling boilerblate
This commit is contained in:
30
lib/util/signals/unix.go
Normal file
30
lib/util/signals/unix.go
Normal 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?
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user