Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added service wrapper code #6220

Merged
merged 9 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ BUG FIXES:
* scheduler: Changes to devices in resource stanza should cause rescheduling [[GH-6644](https://github.com/hashicorp/nomad/issues/6644)]
* api: Decompress web socket response body if gzipped on error responses [[GH-6650](https://github.com/hashicorp/nomad/issues/6650)]
* api: Return a 404 if endpoint not found instead of redirecting to /ui/ [[GH-6658](https://github.com/hashicorp/nomad/issues/6658)]

## 0.10.1 (November 4, 2019)

BUG FIXES:
Expand Down
3 changes: 3 additions & 0 deletions command/agent/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
flaghelper "github.com/hashicorp/nomad/helper/flag-helpers"
gatedwriter "github.com/hashicorp/nomad/helper/gated-writer"
"github.com/hashicorp/nomad/helper/logging"
"github.com/hashicorp/nomad/helper/winsvc"
"github.com/hashicorp/nomad/nomad/structs/config"
"github.com/hashicorp/nomad/version"
"github.com/mitchellh/cli"
Expand Down Expand Up @@ -777,6 +778,8 @@ WAIT:
select {
case s := <-signalCh:
sig = s
case <-winsvc.ShutdownChannel():
sig = os.Interrupt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sig = os.Interrupt
// Treat Windows service shutdown requests as interrupts.
sig = os.Interrupt

case <-c.ShutdownCh:
sig = os.Interrupt
case <-c.retryJoinErrCh:
Expand Down
9 changes: 9 additions & 0 deletions helper/winsvc/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package winsvc

var chanGraceExit = make(chan int)

// ShutdownChannel returns a channel that sends a message that a shutdown
// signal has been received for the service.
func ShutdownChannel() <-chan int {
return chanGraceExit
}
42 changes: 42 additions & 0 deletions helper/winsvc/service_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//+build windows

package winsvc

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

type serviceWindows struct{}

func init() {
interactive, err := wsvc.IsAnInteractiveSession()
if err != nil {
panic(err)
}
// Cannot run as a service when running interactively
if interactive {
return
}
go wsvc.Run("", serviceWindows{})
}

// Execute implements the Windows service Handler type. It will be
// called at the start of the service, and the service will exit
// once Execute completes.
func (serviceWindows) Execute(args []string, r <-chan wsvc.ChangeRequest, s chan<- wsvc.Status) (svcSpecificEC bool, exitCode uint32) {
const accCommands = wsvc.AcceptStop | wsvc.AcceptShutdown
s <- wsvc.Status{State: wsvc.Running, Accepts: accCommands}
for {
c := <-r
switch c.Cmd {
case wsvc.Interrogate:
s <- c.CurrentStatus
case wsvc.Stop, wsvc.Shutdown:
s <- wsvc.Status{State: wsvc.StopPending}
chanGraceExit <- 1
return false, 0
}
}

return false, 0
}
48 changes: 48 additions & 0 deletions vendor/golang.org/x/sys/windows/svc/event.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions vendor/golang.org/x/sys/windows/svc/go12.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions vendor/golang.org/x/sys/windows/svc/go12.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions vendor/golang.org/x/sys/windows/svc/go13.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions vendor/golang.org/x/sys/windows/svc/security.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading