...
1
2
3
4
5
6
7
8 package debug
9
10 import (
11 "os"
12 "os/signal"
13 "syscall"
14
15 "golang.org/x/sys/windows/svc"
16 )
17
18
19
20
21 func Run(name string, handler svc.Handler) error {
22 cmds := make(chan svc.ChangeRequest)
23 changes := make(chan svc.Status)
24
25 sig := make(chan os.Signal, 1)
26 signal.Notify(sig)
27
28 go func() {
29 status := svc.Status{State: svc.Stopped}
30 for {
31 select {
32 case <-sig:
33 cmds <- svc.ChangeRequest{Cmd: svc.Stop, CurrentStatus: status}
34 case status = <-changes:
35 }
36 }
37 }()
38
39 _, errno := handler.Execute([]string{name}, cmds, changes)
40 if errno != 0 {
41 return syscall.Errno(errno)
42 }
43 return nil
44 }
45
View as plain text