-
Notifications
You must be signed in to change notification settings - Fork 3
/
service_status.go
79 lines (68 loc) · 1.84 KB
/
service_status.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"flag"
"fmt"
"runtime"
"github.com/hexops/cmder"
"github.com/hexops/wrench/internal/errors"
"github.com/hexops/wrench/internal/wrench"
)
func init() {
const usage = `
Examples:
Check if wrench is running on the system:
$ wrench service status
`
// Parse flags for our subcommand.
flagSet := flag.NewFlagSet("status", flag.ExitOnError)
// Handles calls to our subcommand.
handler := func(args []string) error {
_ = flagSet.Parse(args)
ok, err := isRoot()
if err != nil {
return errors.Wrap(err, "isRoot")
}
if !ok {
fmt.Println("error: please run as root")
return nil
}
svc, _ := newServiceBot()
status, err := wrench.ServiceStatus(svc)
if err != nil {
return errors.Wrap(err, "ServiceStatus")
}
fmt.Printf("%s registered in %s\n", svc.String(), svc.Platform())
if runtime.GOOS == "darwin" {
fmt.Println("LaunchDaemon: /Library/LaunchDaemons/wrench.plist")
fmt.Println("stdout: /var/log/wrench.out.log")
fmt.Println("stderr: /var/log/wrench.err.log")
}
if runtime.GOOS == "linux" && svc.Platform() == "linux-systemd" {
fmt.Println("systemd: /etc/systemd/system/wrench.service")
fmt.Println("logs: sudo journalctl -u wrench -e -f")
}
if runtime.GOOS == "windows" {
fmt.Println("services: services.msc")
fmt.Println("logs: eventvwr")
}
var cfg wrench.Config
err = wrench.LoadConfig(*serviceConfigFile, &cfg)
if err == nil {
fmt.Println("wrench logs:", cfg.LogFilePath())
}
fmt.Println("")
fmt.Println(status)
return nil
}
// 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)
},
})
}