forked from coreos/fleet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.go
56 lines (48 loc) · 1.28 KB
/
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
package main
import (
"fmt"
"os"
)
var cmdStatusUnits = &Command{
Name: "status",
Summary: "Output the status of one or more units in the cluster",
Usage: "UNIT...",
Description: `Output the status of one or more units currently running in the cluster.
Supports glob matching of units in the current working directory or matches
previously started units.
Show status of a single unit:
fleetctl status foo.service
Show status of an entire directory with glob matching:
fleetctl status myservice/*`,
Run: runStatusUnits,
}
func runStatusUnits(args []string) (exit int) {
for i, v := range args {
// This extra newline here to match systemctl status output
if i != 0 {
fmt.Printf("\n")
}
name := unitNameMangle(v)
exit = printUnitStatus(name)
if exit != 0 {
break
}
}
return
}
func printUnitStatus(jobName string) int {
j, err := cAPI.Job(jobName)
if err != nil {
fmt.Fprintf(os.Stderr, "Error retrieving Job %s: %v", jobName, err)
return 1
}
if j == nil {
fmt.Fprintf(os.Stderr, "Job %s does not exist.\n", jobName)
return 1
} else if j.UnitState == nil {
fmt.Fprintf(os.Stderr, "Job %s does not appear to be running.\n", jobName)
return 1
}
cmd := fmt.Sprintf("systemctl status -l %s", jobName)
return runCommand(cmd, j.UnitState.MachineID)
}