Graceful exits added

This commit is contained in:
Siva 2018-06-20 14:30:17 -04:00
parent 7442f32b94
commit e54fbbba51
3 changed files with 14 additions and 2 deletions

View File

@ -21,6 +21,7 @@ import (
"github.com/hashicorp/consul/command/flags" "github.com/hashicorp/consul/command/flags"
"github.com/hashicorp/consul/lib" "github.com/hashicorp/consul/lib"
"github.com/hashicorp/consul/logger" "github.com/hashicorp/consul/logger"
"github.com/hashicorp/consul/service_os"
"github.com/hashicorp/go-checkpoint" "github.com/hashicorp/go-checkpoint"
multierror "github.com/hashicorp/go-multierror" multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/logutils" "github.com/hashicorp/logutils"
@ -411,6 +412,8 @@ func (c *cmd) run(args []string) int {
case ch := <-agent.ReloadCh(): case ch := <-agent.ReloadCh():
sig = syscall.SIGHUP sig = syscall.SIGHUP
reloadErrCh = ch reloadErrCh = ch
case <-service_os.Shutdown_Channel():
sig = os.Interrupt
case <-c.shutdownCh: case <-c.shutdownCh:
sig = os.Interrupt sig = os.Interrupt
case err := <-agent.RetryJoinCh(): case err := <-agent.RetryJoinCh():

View File

@ -1 +1,7 @@
package service_os package service_os
var chanGraceExit = make(chan int)
func Shutdown_Channel() <-chan int {
return chanGraceExit
}

View File

@ -3,11 +3,12 @@
package service_os package service_os
import ( import (
"os"
wsvc "golang.org/x/sys/windows/svc" wsvc "golang.org/x/sys/windows/svc"
"os"
"time"
) )
type serviceWindows struct {} type serviceWindows struct{}
func init() { func init() {
interactive, err := wsvc.IsAnInteractiveSession() interactive, err := wsvc.IsAnInteractiveSession()
@ -19,6 +20,7 @@ func init() {
} }
go func() { go func() {
_ = wsvc.Run("", serviceWindows{}) _ = wsvc.Run("", serviceWindows{})
time.Sleep(4 * time.Second)
os.Exit(0) os.Exit(0)
}() }()
} }
@ -34,6 +36,7 @@ func (serviceWindows) Execute(args []string, r <-chan wsvc.ChangeRequest, s chan
case wsvc.Interrogate: case wsvc.Interrogate:
s <- c.CurrentStatus s <- c.CurrentStatus
case wsvc.Stop, wsvc.Shutdown: case wsvc.Stop, wsvc.Shutdown:
chanGraceExit <- 1
s <- wsvc.Status{State: wsvc.StopPending} s <- wsvc.Status{State: wsvc.StopPending}
return false, 0 return false, 0
} }