Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

fleetctl: optimize status command #1341

Merged
merged 1 commit into from
Sep 3, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 12 additions & 26 deletions fleetctl/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"

"github.com/coreos/fleet/job"
"github.com/coreos/fleet/schema"
)

var cmdStatusUnits = &Command{
Expand All @@ -44,47 +43,34 @@ func init() {
}

func runStatusUnits(args []string) (exit int) {
units, err := cAPI.Units()
if err != nil {
stderr("Error retrieving unit: %v", err)
return 1
}

uMap := make(map[string]*schema.Unit, len(args))
for _, u := range units {
if u != nil {
u := u
uMap[u.Name] = u
}
}

names := make([]string, len(args))
for i, arg := range args {
name := unitNameMangle(arg)
names[i] = name
unit, err := cAPI.Unit(name)
if err != nil {
stderr("Error retrieving unit: %v", err)
return 1
}

u, ok := uMap[name]
if !ok {
if unit == nil {
stderr("Unit %s does not exist.", name)
return 1
} else if suToGlobal(*u) {
stderr("Unable to determine status of global unit %s.", name)
} else if suToGlobal(*unit) {
stderr("Unable to determine status of global unit %s.", unit.Name)
return 1
} else if job.JobState(u.CurrentState) == job.JobStateInactive {
stderr("Unit %s does not appear to be loaded.", name)
} else if job.JobState(unit.CurrentState) == job.JobStateInactive {
stderr("Unit %s does not appear to be loaded.", unit.Name)
return 1
}
}

for i, name := range names {
// This extra newline is here to match systemctl status output
if i != 0 {
fmt.Printf("\n")
}

if exit = runCommand(uMap[name].MachineID, "systemctl", "status", "-l", name); exit != 0 {
if exit = runCommand(unit.MachineID, "systemctl", "status", "-l", unit.Name); exit != 0 {
break
}
}

return
}