mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-12-24 01:17:56 +08:00
0649d778a7
reduce the number of requests to make([]byte)
32 lines
481 B
Go
32 lines
481 B
Go
// +build !plan9
|
|
|
|
package main
|
|
|
|
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)
|
|
}
|
|
}()
|
|
}
|