1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
14 "golang.org/x/sys/windows/svc"
15 "golang.org/x/sys/windows/svc/debug"
16 "golang.org/x/sys/windows/svc/eventlog"
21 type myservice struct{}
23 func (m *myservice) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {
24 const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown | svc.AcceptPauseAndContinue
25 changes <- svc.Status{State: svc.StartPending}
26 fasttick := time.Tick(500 * time.Millisecond)
27 slowtick := time.Tick(2 * time.Second)
29 changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
39 changes <- c.CurrentStatus
40 // Testing deadlock from https://code.google.com/p/winsvc/issues/detail?id=4
41 time.Sleep(100 * time.Millisecond)
42 changes <- c.CurrentStatus
43 case svc.Stop, svc.Shutdown:
44 // golang.org/x/sys/windows/svc.TestExample is verifying this output.
45 testOutput := strings.Join(args, "-")
46 testOutput += fmt.Sprintf("-%d", c.Context)
47 elog.Info(1, testOutput)
50 changes <- svc.Status{State: svc.Paused, Accepts: cmdsAccepted}
53 changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
56 elog.Error(1, fmt.Sprintf("unexpected control request #%d", c))
60 changes <- svc.Status{State: svc.StopPending}
64 func runService(name string, isDebug bool) {
67 elog = debug.New(name)
69 elog, err = eventlog.Open(name)
76 elog.Info(1, fmt.Sprintf("starting %s service", name))
81 err = run(name, &myservice{})
83 elog.Error(1, fmt.Sprintf("%s service failed: %v", name, err))
86 elog.Info(1, fmt.Sprintf("%s service stopped", name))