Close the shutdown channel instead of sending a value down

This commit is contained in:
Jeff Mitchell
2016-08-01 11:58:45 -04:00
parent 577cd9de35
commit 32b39e808b
3 changed files with 11 additions and 14 deletions

View File

@@ -375,8 +375,6 @@ 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() {
@@ -396,7 +394,7 @@ func (c *ServerCommand) Run(args []string) int {
return true
}
if err := sd.RunServiceDiscovery(&shutdownTriggered, c.WaitGroup, c.ShutdownCh, coreConfig.AdvertiseAddr, activeFunc, sealedFunc); err != nil {
if err := sd.RunServiceDiscovery(c.WaitGroup, c.ShutdownCh, coreConfig.AdvertiseAddr, activeFunc, sealedFunc); err != nil {
c.Ui.Error(fmt.Sprintf("Error initializing service discovery: %v", err))
return 1
}
@@ -421,6 +419,9 @@ func (c *ServerCommand) Run(args []string) int {
// Release the log gate.
logGate.Flush()
// Wait for shutdown
shutdownTriggered := false
for !shutdownTriggered {
select {
case <-c.ShutdownCh:
@@ -757,10 +758,8 @@ func MakeShutdownCh() chan struct{} {
shutdownCh := make(chan os.Signal, 4)
signal.Notify(shutdownCh, os.Interrupt, syscall.SIGTERM)
go func() {
for {
<-shutdownCh
resultCh <- struct{}{}
}
<-shutdownCh
close(resultCh)
}()
return resultCh
}