diff --git a/command/run.go b/command/run.go index 05224361a..9a6668a1d 100644 --- a/command/run.go +++ b/command/run.go @@ -22,17 +22,23 @@ Usage: nomad run [options] Starts running a new job using the definition located at . This is the main command used to invoke new work in Nomad. + Upon successful job submission, this command will immediately + enter an interactive monitor. This is useful to watch Nomad's + internals make scheduling decisions and place the submitted work + onto nodes. The monitor will end once job placement is done. It + is safe to exit the monitor early using ctrl+c. + General Options: ` + generalOptionsUsage() + ` Run Options: - -monitor - On successful job completion, immediately begin monitoring the - evaluation created by the job registration. This mode will - enter an interactive session where status is printed to the - screen, similar to the "tail" UNIX command. + -detach + Return immediately instead of entring monitor mode. After job + submission, the evaluation ID will be printed to the screen. + You can use this ID to start a monitor using the eval-monitor + command later if needed. ` return strings.TrimSpace(helpText) } @@ -42,11 +48,11 @@ func (c *RunCommand) Synopsis() string { } func (c *RunCommand) Run(args []string) int { - var monitor bool + var detach bool flags := c.Meta.FlagSet("run", FlagSetClient) flags.Usage = func() { c.Ui.Output(c.Help()) } - flags.BoolVar(&monitor, "monitor", false, "") + flags.BoolVar(&detach, "detach", false, "") if err := flags.Parse(args); err != nil { return 1 @@ -89,15 +95,15 @@ func (c *RunCommand) Run(args []string) int { } // Check if we should enter monitor mode - if monitor { - mon := newMonitor(c.Ui, client) - return mon.monitor(evalID) + if detach { + c.Ui.Output(evalID) + return 0 } - // By default just print some info and return - c.Ui.Output("JobID = " + job.ID) - c.Ui.Output("EvalID = " + evalID) - return 0 + // Detach was not specified, so start monitoring + mon := newMonitor(c.Ui, client) + return mon.monitor(evalID) + } // convertJob is used to take a *structs.Job and convert it to an *api.Job. diff --git a/command/stop.go b/command/stop.go index e6537ce5c..c7705f9fa 100644 --- a/command/stop.go +++ b/command/stop.go @@ -14,10 +14,10 @@ func (c *StopCommand) Help() string { Usage: nomad stop [options] Stop an existing job. This command is used to signal allocations - to shut down for the given job ID. The shutdown happens - asynchronously, unless the -monitor flag is given, in which case - an interactive monitor session will display log lines as the - job unwinds and completes shutting down. + to shut down for the given job ID. Upon successful deregistraion, + an interactive monitor session will start to display log lines as + the job unwinds its allocations and completes shutting down. It + is safe to exit the monitor early using ctrl+c. General Options: @@ -25,10 +25,11 @@ General Options: Stop Options: - -monitor - Starts an interactive monitor for the job deregistration. This - will display logs in the terminal related to the job shutdown, - and return once the job deregistration has completed. + -detach + Return immediately instead of entering monitor mode. After the + deregister command is submitted, a new evaluation ID is printed + to the screen, which can be used to call up a monitor later if + needed using the eval-monitor command. ` return strings.TrimSpace(helpText) } @@ -38,11 +39,11 @@ func (c *StopCommand) Synopsis() string { } func (c *StopCommand) Run(args []string) int { - var monitor bool + var detach bool flags := c.Meta.FlagSet("stop", FlagSetClient) flags.Usage = func() { c.Ui.Output(c.Help()) } - flags.BoolVar(&monitor, "monitor", false, "") + flags.BoolVar(&detach, "detach", false, "") if err := flags.Parse(args); err != nil { return 1 @@ -76,10 +77,12 @@ func (c *StopCommand) Run(args []string) int { return 1 } - if monitor { - mon := newMonitor(c.Ui, client) - return mon.monitor(evalID) + if detach { + c.Ui.Output(evalID) + return 0 } - return 0 + // Start monitoring the stop eval + mon := newMonitor(c.Ui, client) + return mon.monitor(evalID) }