-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Changes from all commits
20b8448
c1af8f6
42c9b1d
698d538
0bb81e4
54e2f60
a7b4874
f2a4c41
608f4da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} |
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.