-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the basic code to add the Windows Service Manager hooks to Nomad. Includes vendoring golang.org/x/sys/windows/svc and added Docs: * guide for installing as a windows service. * configuration for logging to file from PR #6429
- Loading branch information
Showing
17 changed files
with
871 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.