-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstatus.go
More file actions
39 lines (36 loc) · 1013 Bytes
/
status.go
File metadata and controls
39 lines (36 loc) · 1013 Bytes
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
package fleet
import (
"fmt"
)
// Status prints the systemd status of target unit(s)
func (c *FleetClient) Status(target string) (err error) {
units, err := c.Units(target)
if err != nil {
return
}
for _, unit := range units {
c.printUnitStatus(unit)
fmt.Println()
}
return
}
// printUnitStatus displays the systemd status for a given unit
func (c *FleetClient) printUnitStatus(name string) int {
u, err := c.Fleet.Unit(name)
switch {
case suToGlobal(*u):
fmt.Fprintf(c.errWriter, "Unable to get status for global unit %s. Check the status on the host using systemctl.\n", name)
return 1
case err != nil:
fmt.Fprintf(c.errWriter, "Error retrieving Unit %s: %v\n", name, err)
return 1
case u == nil:
fmt.Fprintf(c.errWriter, "Unit %s does not exist.\n", name)
return 1
case u.CurrentState == "":
fmt.Fprintf(c.errWriter, "Unit %s does not appear to be running.\n", name)
return 1
}
cmd := fmt.Sprintf("systemctl status -l %s", name)
return c.runCommand(cmd, u.MachineID)
}