|
@ -4,8 +4,11 @@ |
|
|
package grace |
|
|
package grace |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog" |
|
|
"os" |
|
|
"os" |
|
|
"os/signal" |
|
|
"os/signal" |
|
|
|
|
|
"reflect" |
|
|
|
|
|
"runtime" |
|
|
"sync" |
|
|
"sync" |
|
|
"syscall" |
|
|
"syscall" |
|
|
) |
|
|
) |
|
@ -16,6 +19,10 @@ var interruptHookLock sync.RWMutex |
|
|
var reloadHooks = make([]func(), 0) |
|
|
var reloadHooks = make([]func(), 0) |
|
|
var reloadHookLock sync.RWMutex |
|
|
var reloadHookLock sync.RWMutex |
|
|
|
|
|
|
|
|
|
|
|
func GetFunctionName(i interface{}) string { |
|
|
|
|
|
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func init() { |
|
|
func init() { |
|
|
signalChan = make(chan os.Signal, 1) |
|
|
signalChan = make(chan os.Signal, 1) |
|
|
signal.Notify(signalChan, |
|
|
signal.Notify(signalChan, |
|
@ -38,6 +45,7 @@ func init() { |
|
|
} else { |
|
|
} else { |
|
|
interruptHookLock.RLock() |
|
|
interruptHookLock.RLock() |
|
|
for _, hook := range interruptHooks { |
|
|
for _, hook := range interruptHooks { |
|
|
|
|
|
glog.V(4).Infof("exec interrupt hook func name:%s", GetFunctionName(hook)) |
|
|
hook() |
|
|
hook() |
|
|
} |
|
|
} |
|
|
interruptHookLock.RUnlock() |
|
|
interruptHookLock.RUnlock() |
|
|