-
Notifications
You must be signed in to change notification settings - Fork 3
/
service_restart.go
54 lines (44 loc) · 1.15 KB
/
service_restart.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
46
47
48
49
50
51
52
53
54
package main
import (
"flag"
"fmt"
"os"
"runtime"
"github.com/hexops/cmder"
"github.com/hexops/wrench/internal/errors"
"github.com/hexops/wrench/internal/wrench/scripts"
)
func init() {
const usage = `
Examples:
Restart wrench:
$ wrench svc restart
`
// Parse flags for our subcommand.
flagSet := flag.NewFlagSet("restart", flag.ExitOnError)
// Handles calls to our subcommand.
handler := func(args []string) error {
_ = flagSet.Parse(args)
service, _ := newServiceBot()
if runtime.GOOS == "darwin" {
// kickstart -k is a better / safer approacher to restarting on macOS.
// https://github.com/kardianos/service/issues/358
if err := scripts.Exec(`launchctl kickstart -k system/wrench`)(os.Stderr); err != nil {
return errors.Wrap(err, "restart")
}
return nil
}
return service.Restart()
}
// Register the command.
serviceCommands = append(serviceCommands, &cmder.Command{
FlagSet: flagSet,
Aliases: []string{},
Handler: handler,
UsageFunc: func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of 'wrench service %s':\n", flagSet.Name())
flagSet.PrintDefaults()
fmt.Printf("%s", usage)
},
})
}