github.com/spg/deis@v1.7.3/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 suToGlobal(*u) {
    25  		fmt.Fprintf(os.Stderr, "Unable to get status for global unit %s. Check the status on the host using systemctl.\n", name)
    26  		return 1
    27  	}
    28  	if err != nil {
    29  		fmt.Fprintf(os.Stderr, "Error retrieving Unit %s: %v", name, err)
    30  		return 1
    31  	}
    32  	if u == nil {
    33  		fmt.Fprintf(os.Stderr, "Unit %s does not exist.\n", name)
    34  		return 1
    35  	} else if u.CurrentState == "" {
    36  		fmt.Fprintf(os.Stderr, "Unit %s does not appear to be running.\n", name)
    37  		return 1
    38  	}
    39  	cmd := fmt.Sprintf("systemctl status -l %s", name)
    40  	return runCommand(cmd, u.MachineID)
    41  }