1
0
Fork 0
mirror of https://github.com/chrislusf/seaweedfs synced 2024-07-03 15:46:44 +02:00
seaweedfs/weed/util/signal_handling.go
2017-06-22 01:33:58 -07:00

32 lines
481 B
Go

// +build !plan9
package util
import (
"os"
"os/signal"
"syscall"
)
func OnInterrupt(fn func()) {
// deal with control+c,etc
signalChan := make(chan os.Signal, 1)
// controlling terminal close, daemon not exit
signal.Ignore(syscall.SIGHUP)
signal.Notify(signalChan,
os.Interrupt,
os.Kill,
syscall.SIGALRM,
// syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
// syscall.SIGQUIT,
)
go func() {
for _ = range signalChan {
fn()
os.Exit(0)
}
}()
}