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.
13
"github.com/gabriel-samfira/sys/windows/svc"
14
"github.com/gabriel-samfira/sys/windows/svc/debug"
15
"github.com/gabriel-samfira/sys/windows/svc/eventlog"
20
type myservice struct{}
22
func (m *myservice) Execute(args []string, r <-chan svc.ChangeRequest, changes chan<- svc.Status) (ssec bool, errno uint32) {
23
const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown | svc.AcceptPauseAndContinue
24
changes <- svc.Status{State: svc.StartPending}
25
fasttick := time.Tick(500 * time.Millisecond)
26
slowtick := time.Tick(2 * time.Second)
28
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
38
changes <- c.CurrentStatus
39
// Testing deadlock from https://code.google.com/p/winsvc/issues/detail?id=4
40
time.Sleep(100 * time.Millisecond)
41
changes <- c.CurrentStatus
42
case svc.Stop, svc.Shutdown:
45
changes <- svc.Status{State: svc.Paused, Accepts: cmdsAccepted}
48
changes <- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
51
elog.Error(1, fmt.Sprintf("unexpected control request #%d", c))
55
changes <- svc.Status{State: svc.StopPending}
59
func runService(name string, isDebug bool) {
62
elog = debug.New(name)
64
elog, err = eventlog.Open(name)
71
elog.Info(1, fmt.Sprintf("starting %s service", name))
76
err = run(name, &myservice{})
78
elog.Error(1, fmt.Sprintf("%s service failed: %v", name, err))
81
elog.Info(1, fmt.Sprintf("%s service stopped", name))