mirror of
https://github.com/hashicorp/vault.git
synced 2026-04-04 16:46:06 -04:00
Sharing shutdown message with physical consul backend
This commit is contained in:
parent
13c4bbf9d7
commit
461c30969e
3 changed files with 9 additions and 8 deletions
|
|
@ -375,6 +375,8 @@ func (c *ServerCommand) Run(args []string) int {
|
|||
|
||||
// Instantiate the wait group
|
||||
c.WaitGroup = &sync.WaitGroup{}
|
||||
// Wait for shutdown
|
||||
shutdownTriggered := false
|
||||
|
||||
// If the backend supports service discovery, run service discovery
|
||||
if coreConfig.HAPhysical != nil && coreConfig.HAPhysical.HAEnabled() {
|
||||
|
|
@ -394,7 +396,7 @@ func (c *ServerCommand) Run(args []string) int {
|
|||
return true
|
||||
}
|
||||
|
||||
if err := sd.RunServiceDiscovery(c.WaitGroup, c.ShutdownCh, coreConfig.AdvertiseAddr, activeFunc, sealedFunc); err != nil {
|
||||
if err := sd.RunServiceDiscovery(&shutdownTriggered, c.WaitGroup, c.ShutdownCh, coreConfig.AdvertiseAddr, activeFunc, sealedFunc); err != nil {
|
||||
c.Ui.Error(fmt.Sprintf("Error initializing service discovery: %v", err))
|
||||
return 1
|
||||
}
|
||||
|
|
@ -419,8 +421,6 @@ func (c *ServerCommand) Run(args []string) int {
|
|||
// Release the log gate.
|
||||
logGate.Flush()
|
||||
|
||||
// Wait for shutdown
|
||||
shutdownTriggered := false
|
||||
for !shutdownTriggered {
|
||||
select {
|
||||
case <-c.ShutdownCh:
|
||||
|
|
|
|||
|
|
@ -416,19 +416,19 @@ func (c *ConsulBackend) checkDuration() time.Duration {
|
|||
return lib.DurationMinusBuffer(c.checkTimeout, checkMinBuffer, checkJitterFactor)
|
||||
}
|
||||
|
||||
func (c *ConsulBackend) RunServiceDiscovery(waitGroup *sync.WaitGroup, shutdownCh ShutdownChannel, advertiseAddr string, activeFunc activeFunction, sealedFunc sealedFunction) (err error) {
|
||||
func (c *ConsulBackend) RunServiceDiscovery(shutdownTriggered *bool, waitGroup *sync.WaitGroup, shutdownCh ShutdownChannel, advertiseAddr string, activeFunc activeFunction, sealedFunc sealedFunction) (err error) {
|
||||
if err := c.setAdvertiseAddr(advertiseAddr); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
waitGroup.Add(1)
|
||||
|
||||
go c.runEventDemuxer(waitGroup, shutdownCh, advertiseAddr, activeFunc, sealedFunc)
|
||||
go c.runEventDemuxer(shutdownTriggered, waitGroup, shutdownCh, advertiseAddr, activeFunc, sealedFunc)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *ConsulBackend) runEventDemuxer(waitGroup *sync.WaitGroup, shutdownCh ShutdownChannel, advertiseAddr string, activeFunc activeFunction, sealedFunc sealedFunction) {
|
||||
func (c *ConsulBackend) runEventDemuxer(shutdownTriggered *bool, waitGroup *sync.WaitGroup, shutdownCh ShutdownChannel, advertiseAddr string, activeFunc activeFunction, sealedFunc sealedFunction) {
|
||||
// Fire the reconcileTimer immediately upon starting the event demuxer
|
||||
reconcileTimer := time.NewTimer(0)
|
||||
defer reconcileTimer.Stop()
|
||||
|
|
@ -453,7 +453,7 @@ func (c *ConsulBackend) runEventDemuxer(waitGroup *sync.WaitGroup, shutdownCh Sh
|
|||
var registeredServiceID string
|
||||
var serviceRegLock int64
|
||||
shutdown:
|
||||
for {
|
||||
for !shutdown {
|
||||
select {
|
||||
case <-c.notifyActiveCh:
|
||||
// Run reconcile immediately upon active state change notification
|
||||
|
|
@ -511,6 +511,7 @@ shutdown:
|
|||
shutdown = true
|
||||
break shutdown
|
||||
}
|
||||
shutdown = *shutdownTriggered
|
||||
}
|
||||
|
||||
c.serviceLock.RLock()
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ type ServiceDiscovery interface {
|
|||
|
||||
// Run executes any background service discovery tasks until the
|
||||
// shutdown channel is closed.
|
||||
RunServiceDiscovery(waitGroup *sync.WaitGroup, shutdownCh ShutdownChannel, advertiseAddr string, activeFunc activeFunction, sealedFunc sealedFunction) error
|
||||
RunServiceDiscovery(shutdownTriggered *bool, waitGroup *sync.WaitGroup, shutdownCh ShutdownChannel, advertiseAddr string, activeFunc activeFunction, sealedFunc sealedFunction) error
|
||||
}
|
||||
|
||||
type Lock interface {
|
||||
|
|
|
|||
Loading…
Reference in a new issue