directory structure change to work with glide
glide has its own requirements. My previous workaround caused me some code checkin errors. Need to fix this.
This commit is contained in:
31
weed/command/signal_handling.go
Normal file
31
weed/command/signal_handling.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// +build !plan9
|
||||
|
||||
package command
|
||||
|
||||
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)
|
||||
}
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user