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/mgr"
17
func startService(name string) error {
18
m, err := mgr.Connect()
23
s, err := m.OpenService(name)
25
return fmt.Errorf("could not access service: %v", err)
28
err = s.Start("is", "manual-started")
30
return fmt.Errorf("could not start service: %v", err)
35
func controlService(name string, c svc.Cmd, to svc.State) error {
36
m, err := mgr.Connect()
41
s, err := m.OpenService(name)
43
return fmt.Errorf("could not access service: %v", err)
46
status, err := s.Control(c)
48
return fmt.Errorf("could not send control=%d: %v", c, err)
50
timeout := time.Now().Add(10 * time.Second)
51
for status.State != to {
52
if timeout.Before(time.Now()) {
53
return fmt.Errorf("timeout waiting for service to go to state=%d", to)
55
time.Sleep(300 * time.Millisecond)
56
status, err = s.Query()
58
return fmt.Errorf("could not retrieve service status: %v", err)