github.com/misfo/deis@v1.0.1-0.20141111224634-e0eee0392b8a/deisctl/backend/fleet/status.go (about) 1 package fleet 2 3 import ( 4 "fmt" 5 "os" 6 ) 7 8 // Status prints the systemd status of target unit(s) 9 func (c *FleetClient) Status(target string) (err error) { 10 units, err := c.Units(target) 11 if err != nil { 12 return 13 } 14 for _, unit := range units { 15 printUnitStatus(unit) 16 fmt.Println() 17 } 18 return 19 } 20 21 // printUnitStatus displays the systemd status for a given unit 22 func printUnitStatus(name string) int { 23 u, err := cAPI.Unit(name) 24 if err != nil { 25 fmt.Fprintf(os.Stderr, "Error retrieving Unit %s: %v", name, err) 26 return 1 27 } 28 if u == nil { 29 fmt.Fprintf(os.Stderr, "Unit %s does not exist.\n", name) 30 return 1 31 } else if u.CurrentState == "" { 32 fmt.Fprintf(os.Stderr, "Unit %s does not appear to be running.\n", name) 33 return 1 34 } 35 cmd := fmt.Sprintf("systemctl status -l %s", name) 36 return runCommand(cmd, u.MachineID) 37 }