Browse Source

master fix interruption through ctrl+c (#3834)

pull/3838/head
Konstantin Lebedev 2 years ago
committed by GitHub
parent
commit
401315f337
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      weed/command/master.go
  2. 8
      weed/util/grace/signal_handling.go

2
weed/command/master.go

@ -255,7 +255,7 @@ func startMaster(masterOption MasterOptions, masterWhiteList []string) {
} }
grace.OnInterrupt(ms.Shutdown) grace.OnInterrupt(ms.Shutdown)
grace.OnInterrupt(grpcS.GracefulStop)
grace.OnInterrupt(grpcS.Stop)
grace.OnReload(func() { grace.OnReload(func() {
if ms.Topo.HashicorpRaft != nil && ms.Topo.HashicorpRaft.State() == hashicorpRaft.Leader { if ms.Topo.HashicorpRaft != nil && ms.Topo.HashicorpRaft.State() == hashicorpRaft.Leader {
ms.Topo.HashicorpRaft.LeadershipTransfer() ms.Topo.HashicorpRaft.LeadershipTransfer()

8
weed/util/grace/signal_handling.go

@ -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()

Loading…
Cancel
Save