1
0
mirror of https://github.com/rancher/os.git synced 2025-04-28 19:34:45 +00:00
os/cmd/control/switch_console.go

50 lines
1.0 KiB
Go
Raw Normal View History

package control
2016-06-06 22:13:15 +00:00
import (
"errors"
2016-06-06 22:13:15 +00:00
"github.com/rancher/os/config"
2018-09-16 04:55:26 +00:00
"github.com/rancher/os/pkg/compose"
"github.com/rancher/os/pkg/log"
"github.com/codegangsta/cli"
"github.com/docker/libcompose/project/options"
2016-06-06 22:13:15 +00:00
"golang.org/x/net/context"
)
func switchConsoleAction(c *cli.Context) error {
if len(c.Args()) != 1 {
return errors.New("Must specify exactly one existing container")
2016-06-06 22:13:15 +00:00
}
newConsole := c.Args()[0]
2016-06-06 22:13:15 +00:00
cfg := config.LoadConfig()
project, err := compose.GetProject(cfg, true, false)
2016-06-06 22:13:15 +00:00
if err != nil {
return err
2016-06-06 22:13:15 +00:00
}
if newConsole != "default" {
if err = compose.LoadSpecialService(project, cfg, "console", newConsole); err != nil {
return err
}
2016-06-06 22:13:15 +00:00
}
2016-06-28 18:18:26 +00:00
if err = config.Set("rancher.console", newConsole); err != nil {
log.Errorf("Failed to update 'rancher.console': %v", err)
}
if err = project.Up(context.Background(), options.Up{
Log: true,
}, "console"); err != nil {
return err
2016-06-06 22:13:15 +00:00
}
if err = project.Restart(context.Background(), 10, "docker"); err != nil {
log.Errorf("Failed to restart Docker: %v", err)
}
return nil
2016-06-06 22:13:15 +00:00
}