mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-12-02 08:36:57 +08:00
28 lines
374 B
Go
28 lines
374 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)
|
|
signal.Notify(signalChan,
|
|
os.Interrupt,
|
|
os.Kill,
|
|
syscall.SIGHUP,
|
|
syscall.SIGINT,
|
|
syscall.SIGTERM,
|
|
syscall.SIGQUIT)
|
|
go func() {
|
|
for _ = range signalChan {
|
|
fn()
|
|
os.Exit(0)
|
|
}
|
|
}()
|
|
}
|