From c4c8ec402c6693c5946be2c62bccc2d42939c22c Mon Sep 17 00:00:00 2001 From: Josh Curl Date: Sun, 12 Jun 2016 22:28:24 -0700 Subject: [PATCH] Add 'ros console enable' command --- cmd/control/console.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/cmd/control/console.go b/cmd/control/console.go index be15a989..9bd25a51 100644 --- a/cmd/control/console.go +++ b/cmd/control/console.go @@ -20,7 +20,7 @@ func consoleSubcommands() []cli.Command { return []cli.Command{ { Name: "switch", - Usage: "switch currently running console", + Usage: "switch console without a reboot", Action: consoleSwitch, Flags: []cli.Flag{ cli.BoolFlag{ @@ -29,6 +29,11 @@ func consoleSubcommands() []cli.Command { }, }, }, + { + Name: "enable", + Usage: "set console to be switched on next reboot", + Action: consoleEnable, + }, { Name: "list", Usage: "list available consoles", @@ -39,7 +44,7 @@ func consoleSubcommands() []cli.Command { func consoleSwitch(c *cli.Context) error { if len(c.Args()) != 1 { - log.Fatal("Must specify exactly one existing container") + log.Fatal("Must specify exactly one console to switch to") } newConsole := c.Args()[0] @@ -85,6 +90,27 @@ func consoleSwitch(c *cli.Context) error { return service.Log(context.Background(), true) } +func consoleEnable(c *cli.Context) error { + if len(c.Args()) != 1 { + log.Fatal("Must specify exactly one console to enable") + } + newConsole := c.Args()[0] + + cfg := config.LoadConfig() + + if newConsole != "default" { + if err := compose.StageServices(cfg, newConsole); err != nil { + return err + } + } + + if err := config.Set("rancher.console", newConsole); err != nil { + log.Errorf("Failed to update 'rancher.console': %v", err) + } + + return nil +} + func consoleList(c *cli.Context) error { cfg := config.LoadConfig()