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

Move Windows Service init out to seperate package #2061

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
Lint
Signed-off-by: Jamie Milton <jammiemil@hotmail.com>
  • Loading branch information
jammiemil committed Aug 25, 2022
commit cf3a650b3622e72967e12e492c14652564c1188a
12 changes: 7 additions & 5 deletions cmd/agent/initiate/initiate_windows.go
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import (
"golang.org/x/sys/windows/svc"
)

// Default name for the Grafana Agent under Windows
const (
ServiceName = "Grafana Agent"
)
@@ -28,6 +29,7 @@ func init() {

const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown

// Channel to inform server of service stop request
var ServiceExit = make(chan bool)

// AgentService runs the Grafana Agent as a service.
@@ -36,22 +38,22 @@ type AgentService struct {
}

// Execute starts the AgentService.
func (m *AgentService) Execute(args []string, serviceRequests <-chan svc.ChangeRequest, service_changes chan<- svc.Status) (ssec bool, errno uint32) {
service_changes <- svc.Status{State: svc.StartPending}
func (m *AgentService) Execute(args []string, serviceRequests <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {
changes <- svc.Status{State: svc.StartPending}

// Pause is not accepted, we immediately set the service as running and trigger the entrypoint load in the background
// this is because the WAL is reloaded and the timeout for a windows service starting is 30 seconds. In this case
// the service is running but Agent may still be starting up reading the WAL and doing other operations.

service_changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}

loop:
for {
select {
case c := <-serviceRequests:
switch c.Cmd {
case svc.Interrogate:
service_changes <- c.CurrentStatus
changes <- c.CurrentStatus
case svc.Stop, svc.Shutdown:
//We need to send a message back to stop the process if this happens
m.stopCh <- true
@@ -69,7 +71,7 @@ loop:
//if ep != nil {
// ep.Stop()
//}
service_changes <- svc.Status{State: svc.StopPending}
changes <- svc.Status{State: svc.StopPending}
return
}