forked from kbudde/rabbitmq_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_windows.go
45 lines (41 loc) · 1019 Bytes
/
service_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
log "github.com/sirupsen/logrus"
"golang.org/x/sys/windows/svc"
)
func runService() chan bool {
stopCh := make(chan bool)
isInteractive, err := svc.IsAnInteractiveSession()
if err != nil {
log.Fatal(err)
}
if !isInteractive {
go svc.Run(serviceName, &rmqExporterService{stopCh: stopCh})
}
return stopCh
}
type rmqExporterService struct {
stopCh chan<- bool
}
func (s *rmqExporterService) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {
const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown
changes <- svc.Status{State: svc.StartPending}
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
loop:
for {
select {
case c := <-r:
switch c.Cmd {
case svc.Interrogate:
changes <- c.CurrentStatus
case svc.Stop, svc.Shutdown:
s.stopCh <- true
break loop
default:
log.Error("unexpected control request ", c)
}
}
changes <- svc.Status{State: svc.StopPending}
}
return
}