mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
[volume] Add new volumes to HUP(reload) signal (#3755)
Add new volumes to HUP(reload) signal
This commit is contained in:
parent
47fd5d3fa1
commit
301b678147
|
@ -265,6 +265,8 @@ func (v VolumeServerOptions) startVolumeServer(volumeFolders, maxVolumeCounts, v
|
|||
// starting the cluster http server
|
||||
clusterHttpServer := v.startClusterHttpService(volumeMux)
|
||||
|
||||
grace.OnReload(volumeServer.LoadNewVolumes)
|
||||
|
||||
stopChan := make(chan bool)
|
||||
grace.OnInterrupt(func() {
|
||||
fmt.Println("volume server has been killed")
|
||||
|
|
|
@ -137,6 +137,11 @@ func (vs *VolumeServer) SetStopping() {
|
|||
vs.store.SetStopping()
|
||||
}
|
||||
|
||||
func (vs *VolumeServer) LoadNewVolumes() {
|
||||
glog.V(0).Infoln(" Loading new volume ids ...")
|
||||
vs.store.LoadNewVolumes()
|
||||
}
|
||||
|
||||
func (vs *VolumeServer) Shutdown() {
|
||||
glog.V(0).Infoln("Shutting down volume server...")
|
||||
vs.store.Close()
|
||||
|
|
|
@ -361,6 +361,12 @@ func (s *Store) SetStopping() {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Store) LoadNewVolumes() {
|
||||
for _, location := range s.Locations {
|
||||
location.loadExistingVolumes(s.NeedleMapKind)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Store) Close() {
|
||||
for _, location := range s.Locations {
|
||||
location.Close()
|
||||
|
|
|
@ -11,39 +11,55 @@ import (
|
|||
)
|
||||
|
||||
var signalChan chan os.Signal
|
||||
var hooks = make([]func(), 0)
|
||||
var hookLock sync.RWMutex
|
||||
var interruptHooks = make([]func(), 0)
|
||||
var interruptHookLock sync.RWMutex
|
||||
var reloadHooks = make([]func(), 0)
|
||||
var reloadHookLock sync.RWMutex
|
||||
|
||||
func init() {
|
||||
signalChan = make(chan os.Signal, 1)
|
||||
signal.Ignore(syscall.SIGHUP)
|
||||
signal.Notify(signalChan,
|
||||
os.Interrupt,
|
||||
os.Kill,
|
||||
syscall.SIGALRM,
|
||||
// syscall.SIGHUP,
|
||||
syscall.SIGHUP,
|
||||
syscall.SIGINT,
|
||||
syscall.SIGTERM,
|
||||
// syscall.SIGQUIT,
|
||||
)
|
||||
go func() {
|
||||
for range signalChan {
|
||||
hookLock.RLock()
|
||||
for _, hook := range hooks {
|
||||
hook()
|
||||
for s := range signalChan {
|
||||
if s.String() == syscall.SIGHUP.String() {
|
||||
reloadHookLock.RLock()
|
||||
for _, hook := range reloadHooks {
|
||||
hook()
|
||||
}
|
||||
reloadHookLock.RUnlock()
|
||||
} else {
|
||||
interruptHookLock.RLock()
|
||||
for _, hook := range interruptHooks {
|
||||
hook()
|
||||
}
|
||||
interruptHookLock.RUnlock()
|
||||
os.Exit(0)
|
||||
}
|
||||
hookLock.RUnlock()
|
||||
os.Exit(0)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func OnReload(fn func()) {
|
||||
// prevent reentry
|
||||
reloadHookLock.Lock()
|
||||
defer reloadHookLock.Unlock()
|
||||
reloadHooks = append(reloadHooks, fn)
|
||||
}
|
||||
|
||||
func OnInterrupt(fn func()) {
|
||||
// prevent reentry
|
||||
hookLock.Lock()
|
||||
defer hookLock.Unlock()
|
||||
interruptHookLock.Lock()
|
||||
defer interruptHookLock.Unlock()
|
||||
|
||||
// deal with control+c,etc
|
||||
// controlling terminal close, daemon not exit
|
||||
hooks = append(hooks, fn)
|
||||
interruptHooks = append(interruptHooks, fn)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue