github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/worker/uniter/runner/jujuc/reboot.go (about) 1 package jujuc 2 3 import ( 4 "github.com/juju/cmd" 5 "github.com/juju/errors" 6 "launchpad.net/gnuflag" 7 ) 8 9 // JujuRebootCommand implements the juju-reboot command. 10 type JujuRebootCommand struct { 11 cmd.CommandBase 12 ctx Context 13 Now bool 14 } 15 16 func NewJujuRebootCommand(ctx Context) (cmd.Command, error) { 17 return &JujuRebootCommand{ctx: ctx}, nil 18 } 19 20 func (c *JujuRebootCommand) Info() *cmd.Info { 21 doc := ` 22 juju-reboot causes the host machine to reboot, after stopping all containers 23 hosted on the machine. 24 25 An invocation without arguments will allow the current hook to complete, and 26 will only cause a reboot if the hook completes successfully. 27 28 If the --now flag is passed, the current hook will terminate immediately, and 29 be restarted from scratch after reboot. This allows charm authors to write 30 hooks that need to reboot more than once in the course of installing software. 31 32 The --now flag cannot terminate a debug-hooks session; hooks using --now should 33 be sure to terminate on unexpected errors, so as to guarantee expected behaviour 34 in all situations. 35 36 juju-reboot is not supported when running actions. 37 ` 38 return &cmd.Info{ 39 Name: "juju-reboot", 40 Args: "", 41 Purpose: "Reboot the host machine", 42 Doc: doc, 43 } 44 } 45 46 func (c *JujuRebootCommand) SetFlags(f *gnuflag.FlagSet) { 47 f.BoolVar(&c.Now, "now", false, "reboot immediately, killing the invoking process") 48 } 49 50 func (c *JujuRebootCommand) Init(args []string) error { 51 return cmd.CheckEmpty(args) 52 } 53 54 func (c *JujuRebootCommand) Run(ctx *cmd.Context) error { 55 if _, err := c.ctx.ActionParams(); err == nil { 56 return errors.New("juju-reboot is not supported when running an action.") 57 } 58 59 rebootPriority := RebootAfterHook 60 if c.Now { 61 rebootPriority = RebootNow 62 } 63 64 return c.ctx.RequestReboot(rebootPriority) 65 }