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