seaweedfs/go/weed/signal_handling.go

29 lines
393 B
Go
Raw Normal View History

2014-05-14 06:04:04 +08:00
// +build !plan9
package main
import (
"os"
"os/signal"
"syscall"
)
func OnInterrupt(fn func()) {
// deal with control+c,etc
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan,
os.Interrupt,
os.Kill,
2014-05-14 10:26:05 +08:00
syscall.SIGALRM,
2014-05-14 06:04:04 +08:00
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
for _ = range signalChan {
fn()
os.Exit(0)
}
}()
}