Skip to content

Commit

Permalink
Graceful exits added
Browse files Browse the repository at this point in the history
  • Loading branch information
MagnumOpus21 committed Jun 20, 2018
1 parent bf26498 commit 319a0ae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/hashicorp/consul/command/flags"
"github.com/hashicorp/consul/lib"
"github.com/hashicorp/consul/logger"
"github.com/hashicorp/consul/service_os"
"github.com/hashicorp/go-checkpoint"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/logutils"
Expand Down Expand Up @@ -411,6 +412,8 @@ func (c *cmd) run(args []string) int {
case ch := <-agent.ReloadCh():
sig = syscall.SIGHUP
reloadErrCh = ch
case <-service_os.Shutdown_Channel():
sig = os.Interrupt
case <-c.shutdownCh:
sig = os.Interrupt
case err := <-agent.RetryJoinCh():
Expand Down
6 changes: 6 additions & 0 deletions service_os/service.go
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
package service_os

var chanGraceExit = make(chan int)

func Shutdown_Channel() <-chan int {
return chanGraceExit
}
7 changes: 5 additions & 2 deletions service_os/service_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
package service_os

import (
"os"
wsvc "golang.org/x/sys/windows/svc"
"os"
"time"
)

type serviceWindows struct {}
type serviceWindows struct{}

func init() {
interactive, err := wsvc.IsAnInteractiveSession()
Expand All @@ -19,6 +20,7 @@ func init() {
}
go func() {
_ = wsvc.Run("", serviceWindows{})
time.Sleep(4 * time.Second)
os.Exit(0)
}()
}
Expand All @@ -34,6 +36,7 @@ func (serviceWindows) Execute(args []string, r <-chan wsvc.ChangeRequest, s chan
case wsvc.Interrogate:
s <- c.CurrentStatus
case wsvc.Stop, wsvc.Shutdown:
chanGraceExit <- 1
s <- wsvc.Status{State: wsvc.StopPending}
return false, 0
}
Expand Down

0 comments on commit 319a0ae

Please sign in to comment.