consul/service_os/service_windows.go

47 lines
924 B
Go
Raw Normal View History

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
//go:build windows
// +build windows
2018-06-18 18:49:59 +00:00
package service_os
import (
wsvc "golang.org/x/sys/windows/svc"
)
2018-06-20 18:30:17 +00:00
type serviceWindows struct{}
2018-06-18 18:49:59 +00:00
func init() {
interactive, err := wsvc.IsAnInteractiveSession()
if err != nil {
panic(err)
}
if interactive {
return
}
go func() {
_ = wsvc.Run("", serviceWindows{})
}()
}
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.StartPending}
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:
2018-06-20 18:30:17 +00:00
chanGraceExit <- 1
2018-06-18 18:49:59 +00:00
s <- wsvc.Status{State: wsvc.StopPending}
return false, 0
}
}
return false, 0
}