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

Commit

Permalink
Rebased against master
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorj2f committed Aug 8, 2016
1 parent dce0de7 commit b39e193
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 219 deletions.
121 changes: 0 additions & 121 deletions Godeps/Godeps.json

This file was deleted.

53 changes: 27 additions & 26 deletions fleetctl/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,43 @@ package main
import (
"os"

"github.com/spf13/cobra"

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

var (
cmdLoadUnits = &Command{
Name: "load",
Summary: "Schedule one or more units in the cluster, first submitting them if necessary.",
Usage: "[--no-block|--block-attempts=N] UNIT...",
Description: `Load one or many units in the cluster into systemd, but do not start.
var cmdLoad = &cobra.Command{
Use: "load [--no-block|--block-attempts=N] UNIT...",
Short: "Schedule one or more units in the cluster, first submitting them if necessary.",
Long: `Load one or many units in the cluster into systemd, but do not start.
Select units to load by glob matching for units in the current working directory
Select units to load by glob matching for units in the current working directory
or matching the names of previously submitted units.
For units which are not global, load operations are performed synchronously,
which means fleetctl will block until it detects that the unit(s) have
transitioned to a loaded state. This behaviour can be configured with the
respective --block-attempts and --no-block options. Load operations on global
units are always non-blocking.`,
Run: runLoadUnits,
}
)
Run: runWrapper(runLoadUnit),
}

func init() {
cmdLoadUnits.Flags.BoolVar(&sharedFlags.Sign, "sign", false, "DEPRECATED - this option cannot be used")
cmdLoadUnits.Flags.IntVar(&sharedFlags.BlockAttempts, "block-attempts", 0, "Wait until the jobs are loaded, performing up to N attempts before giving up. A value of 0 indicates no limit. Does not apply to global units.")
cmdLoadUnits.Flags.BoolVar(&sharedFlags.NoBlock, "no-block", false, "Do not wait until the jobs have been loaded before exiting. Always the case for global units.")
cmdFleet.AddCommand(cmdLoad)

cmdLoad.Flags().BoolVar(&sharedFlags.Sign, "sign", false, "DEPRECATED - this option cannot be used")
cmdLoad.Flags().IntVar(&sharedFlags.BlockAttempts, "block-attempts", 0, "Wait until the jobs are loaded, performing up to N attempts before giving up. A value of 0 indicates no limit. Does not apply to global units.")
cmdLoad.Flags().BoolVar(&sharedFlags.NoBlock, "no-block", false, "Do not wait until the jobs have been loaded before exiting. Always the case for global units.")
cmdLoad.Flags().BoolVar(&sharedFlags.Replace, "replace", false, "Replace the old scheduled units in the cluster with new versions.")
}

func runLoadUnits(args []string) (exit int) {
if err := lazyCreateUnits(args); err != nil {
func runLoadUnit(cCmd *cobra.Command, args []string) (exit int) {
if len(args) == 0 {
stderr("No units given")
return 0
}

if err := lazyCreateUnits(cCmd, args); err != nil {
stderr("Error creating units: %v", err)
return 1
}
Expand All @@ -66,17 +73,11 @@ func runLoadUnits(args []string) (exit int) {
}
}

if !sharedFlags.NoBlock {
errchan := waitForUnitStates(loading, job.JobStateLoaded, sharedFlags.BlockAttempts, os.Stdout)
for err := range errchan {
stderr("Error waiting for units: %v", err)
exit = 1
}
} else {
for _, name := range loading {
stdout("Triggered unit %s load", name)
}
exitVal := tryWaitForUnitStates(loading, "load", job.JobStateLoaded, getBlockAttempts(cCmd), os.Stdout)
if exitVal != 0 {
stderr("Error waiting for unit states, exit status: %d", exitVal)
return 1
}

return
return 0
}
53 changes: 27 additions & 26 deletions fleetctl/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ package main
import (
"os"

"github.com/spf13/cobra"

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

var (
cmdStartUnit = &Command{
Name: "start",
Summary: "Instruct systemd to start one or more units in the cluster, first submitting and loading if necessary.",
Usage: "[--no-block|--block-attempts=N] UNIT...",
Description: `Start one or many units on the cluster. Select units to start by glob matching
var cmdStart = &cobra.Command{
Use: "start [--no-block|--block-attempts=N] UNIT...",
Short: "Instruct systemd to start one or more units in the cluster, first submitting and loading if necessary.",
Long: `Start one or many units on the cluster. Select units to start by glob matching
for units in the current working directory or matching names of previously
submitted units.
Expand All @@ -36,25 +36,32 @@ respective --block-attempts and --no-block options. Start operations on global
units are always non-blocking.
Start a single unit:
fleetctl start foo.service
fleetctl start foo.service
Start an entire directory of units with glob matching:
fleetctl start myservice/*
fleetctl start myservice/*
You may filter suitable hosts based on metadata provided by the machine.
Machine metadata is located in the fleet configuration file.`,
Run: runStartUnit,
}
)
Run: runWrapper(runStartUnit),
}

func init() {
cmdStartUnit.Flags.BoolVar(&sharedFlags.Sign, "sign", false, "DEPRECATED - this option cannot be used")
cmdStartUnit.Flags.IntVar(&sharedFlags.BlockAttempts, "block-attempts", 0, "Wait until the units are launched, performing up to N attempts before giving up. A value of 0 indicates no limit. Does not apply to global units.")
cmdStartUnit.Flags.BoolVar(&sharedFlags.NoBlock, "no-block", false, "Do not wait until the units have launched before exiting. Always the case for global units.")
cmdFleet.AddCommand(cmdStart)

cmdStart.Flags().BoolVar(&sharedFlags.Sign, "sign", false, "DEPRECATED - this option cannot be used")
cmdStart.Flags().IntVar(&sharedFlags.BlockAttempts, "block-attempts", 0, "Wait until the units are launched, performing up to N attempts before giving up. A value of 0 indicates no limit. Does not apply to global units.")
cmdStart.Flags().BoolVar(&sharedFlags.NoBlock, "no-block", false, "Do not wait until the units have launched before exiting. Always the case for global units.")
cmdStart.Flags().BoolVar(&sharedFlags.Replace, "replace", false, "Replace the already started units in the cluster with new versions.")
}

func runStartUnit(args []string) (exit int) {
if err := lazyCreateUnits(args); err != nil {
func runStartUnit(cCmd *cobra.Command, args []string) (exit int) {
if len(args) == 0 {
stderr("No units given")
return 0
}

if err := lazyCreateUnits(cCmd, args); err != nil {
stderr("Error creating units: %v", err)
return 1
}
Expand All @@ -74,16 +81,10 @@ func runStartUnit(args []string) (exit int) {
}
}

if !sharedFlags.NoBlock {
errchan := waitForUnitStates(starting, job.JobStateLaunched, sharedFlags.BlockAttempts, os.Stdout)
for err := range errchan {
stderr("Error waiting for units: %v", err)
exit = 1
}
} else {
for _, name := range starting {
stdout("Triggered unit %s start", name)
}
exitVal := tryWaitForUnitStates(starting, "start", job.JobStateLaunched, getBlockAttempts(cCmd), os.Stdout)
if exitVal != 0 {
stderr("Error waiting for unit states, exit status: %d", exitVal)
return exitVal
}

exitVal = tryWaitForSystemdActiveState(starting)
Expand Down
43 changes: 23 additions & 20 deletions fleetctl/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ package main
import (
"os"

"github.com/spf13/cobra"

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

var cmdStopUnit = &Command{
Name: "stop",
Summary: "Instruct systemd to stop one or more units in the cluster.",
Usage: "[--no-block|--block-attempts=N] UNIT...",
Description: `Stop one or more units from running in the cluster, but allow them to be
var cmdStop = &cobra.Command{
Use: "stop [--no-block|--block-attempts=N] UNIT...",
Short: "Instruct systemd to stop one or more units in the cluster.",
Long: `Stop one or more units from running in the cluster, but allow them to be
started again in the future.
Instructs systemd on the host machine to stop the unit, deferring to systemd
Expand All @@ -39,19 +40,26 @@ respective --block-attempts and --no-block options. Stop operations on global
units are always non-blocking.
Stop a single unit:
fleetctl stop foo.service
fleetctl stop foo.service
Stop an entire directory of units with glob matching, without waiting:
fleetctl --no-block stop myservice/*`,
Run: runStopUnit,
fleetctl --no-block stop myservice/*`,
Run: runWrapper(runStopUnit),
}

func init() {
cmdStopUnit.Flags.IntVar(&sharedFlags.BlockAttempts, "block-attempts", 0, "Wait until the units are stopped, performing up to N attempts before giving up. A value of 0 indicates no limit. Does not apply to global units.")
cmdStopUnit.Flags.BoolVar(&sharedFlags.NoBlock, "no-block", false, "Do not wait until the units have stopped before exiting. Always the case for global units.")
cmdFleet.AddCommand(cmdStop)

cmdStop.Flags().IntVar(&sharedFlags.BlockAttempts, "block-attempts", 0, "Wait until the units are stopped, performing up to N attempts before giving up. A value of 0 indicates no limit. Does not apply to global units.")
cmdStop.Flags().BoolVar(&sharedFlags.NoBlock, "no-block", false, "Do not wait until the units have stopped before exiting. Always the case for global units.")
}

func runStopUnit(args []string) (exit int) {
func runStopUnit(cCmd *cobra.Command, args []string) (exit int) {
if len(args) == 0 {
stderr("No units given")
return 0
}

units, err := findUnits(args)
if err != nil {
stderr("%v", err)
Expand Down Expand Up @@ -84,16 +92,11 @@ func runStopUnit(args []string) (exit int) {
}
}

if !sharedFlags.NoBlock {
errchan := waitForUnitStates(stopping, job.JobStateLoaded, sharedFlags.BlockAttempts, os.Stdout)
for err := range errchan {
stderr("Error waiting for units: %v", err)
exit = 1
}
exit = tryWaitForUnitStates(stopping, "stop", job.JobStateLoaded, getBlockAttempts(cCmd), os.Stdout)
if exit == 0 {
stderr("Successfully stopped units %v.", stopping)
} else {
for _, name := range stopping {
stdout("Triggered unit %s stop", name)
}
stderr("Failed to stop units %v. exit == %d.", stopping, exit)
}

return
Expand Down
Loading

0 comments on commit b39e193

Please sign in to comment.