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