mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
master fix interruption through ctrl+c (#3834)
This commit is contained in:
parent
a05725aea6
commit
401315f337
|
@ -255,7 +255,7 @@ func startMaster(masterOption MasterOptions, masterWhiteList []string) {
|
|||
}
|
||||
|
||||
grace.OnInterrupt(ms.Shutdown)
|
||||
grace.OnInterrupt(grpcS.GracefulStop)
|
||||
grace.OnInterrupt(grpcS.Stop)
|
||||
grace.OnReload(func() {
|
||||
if ms.Topo.HashicorpRaft != nil && ms.Topo.HashicorpRaft.State() == hashicorpRaft.Leader {
|
||||
ms.Topo.HashicorpRaft.LeadershipTransfer()
|
||||
|
|
|
@ -4,8 +4,11 @@
|
|||
package grace
|
||||
|
||||
import (
|
||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||
"os"
|
||||
"os/signal"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sync"
|
||||
"syscall"
|
||||
)
|
||||
|
@ -16,6 +19,10 @@ var interruptHookLock sync.RWMutex
|
|||
var reloadHooks = make([]func(), 0)
|
||||
var reloadHookLock sync.RWMutex
|
||||
|
||||
func GetFunctionName(i interface{}) string {
|
||||
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
|
||||
}
|
||||
|
||||
func init() {
|
||||
signalChan = make(chan os.Signal, 1)
|
||||
signal.Notify(signalChan,
|
||||
|
@ -38,6 +45,7 @@ func init() {
|
|||
} else {
|
||||
interruptHookLock.RLock()
|
||||
for _, hook := range interruptHooks {
|
||||
glog.V(4).Infof("exec interrupt hook func name:%s", GetFunctionName(hook))
|
||||
hook()
|
||||
}
|
||||
interruptHookLock.RUnlock()
|
||||
|
|
Loading…
Reference in a new issue