diff --git a/cmd/control/console.go b/cmd/control/console.go index b262c6e2..be15a989 100644 --- a/cmd/control/console.go +++ b/cmd/control/console.go @@ -13,8 +13,6 @@ import ( "github.com/docker/libcompose/project/options" "github.com/rancher/os/compose" "github.com/rancher/os/config" - "github.com/rancher/os/docker" - "github.com/rancher/os/util" "github.com/rancher/os/util/network" ) @@ -56,23 +54,10 @@ func consoleSwitch(c *cli.Context) error { cfg := config.LoadConfig() - if err := compose.StageServices(cfg, newConsole); err != nil { - return err - } - - client, err := docker.NewSystemClient() - if err != nil { - return err - } - - currentContainerId, err := util.GetCurrentContainerId() - if err != nil { - return err - } - - currentContainer, err := client.ContainerInspect(context.Background(), currentContainerId) - if err != nil { - return err + if newConsole != "default" { + if err := compose.StageServices(cfg, newConsole); err != nil { + return err + } } service, err := compose.CreateService(nil, "switch-console", &composeConfig.ServiceConfigV1{ @@ -80,7 +65,7 @@ func consoleSwitch(c *cli.Context) error { Privileged: true, Net: "host", Pid: "host", - Image: currentContainer.Config.Image, + Image: fmt.Sprintf("rancher/os-base:%s", config.VERSION), Labels: map[string]string{ config.SCOPE: config.SYSTEM, }, @@ -94,9 +79,10 @@ func consoleSwitch(c *cli.Context) error { if err = service.Delete(context.Background(), options.Delete{}); err != nil { return err } - return service.Up(context.Background(), options.Up{ - Log: true, - }) + if err = service.Up(context.Background(), options.Up{}); err != nil { + return err + } + return service.Log(context.Background(), true) } func consoleList(c *cli.Context) error { @@ -107,6 +93,7 @@ func consoleList(c *cli.Context) error { return err } + fmt.Println("default") for _, console := range consoles { fmt.Println(console) } diff --git a/cmd/control/service.go b/cmd/control/service.go index 47a61832..b681804c 100644 --- a/cmd/control/service.go +++ b/cmd/control/service.go @@ -19,7 +19,7 @@ type projectFactory struct { func (p *projectFactory) Create(c *cli.Context) (project.APIProject, error) { cfg := config.LoadConfig() - return compose.GetProject(cfg, true) + return compose.GetProject(cfg, true, false) } func beforeApp(c *cli.Context) error { diff --git a/cmd/switchconsole/switch_console.go b/cmd/switchconsole/switch_console.go index 10d558f6..fef54ea6 100644 --- a/cmd/switchconsole/switch_console.go +++ b/cmd/switchconsole/switch_console.go @@ -18,13 +18,15 @@ func Main() { cfg := config.LoadConfig() - project, err := compose.GetProject(cfg, true) + project, err := compose.GetProject(cfg, true, false) if err != nil { log.Fatal(err) } - if err = compose.LoadService(project, cfg, true, newConsole); err != nil { - log.Fatal(err) + if newConsole != "default" { + if err = compose.LoadService(project, cfg, true, newConsole); err != nil { + log.Fatal(err) + } } if err = project.Up(context.Background(), options.Up{ diff --git a/cmd/userdocker/main.go b/cmd/userdocker/main.go index f1fb8281..08b2b097 100644 --- a/cmd/userdocker/main.go +++ b/cmd/userdocker/main.go @@ -102,7 +102,7 @@ func startDocker(cfg *config.CloudConfig) (string, types.HijackedResponse, error log.Infof("Starting Docker in context: %s", storageContext) - p, err := compose.GetProject(cfg, true) + p, err := compose.GetProject(cfg, true, false) if err != nil { return "", types.HijackedResponse{}, err } diff --git a/compose/project.go b/compose/project.go index 10062107..37b4905e 100644 --- a/compose/project.go +++ b/compose/project.go @@ -56,8 +56,8 @@ func RunServiceSet(name string, cfg *config.CloudConfig, configs map[string]*com }) } -func GetProject(cfg *config.CloudConfig, networkingAvailable bool) (*project.Project, error) { - return newCoreServiceProject(cfg, networkingAvailable) +func GetProject(cfg *config.CloudConfig, networkingAvailable, loadConsole bool) (*project.Project, error) { + return newCoreServiceProject(cfg, networkingAvailable, loadConsole) } func newProject(name string, cfg *config.CloudConfig, environmentLookup composeConfig.EnvironmentLookup, authLookup *rosDocker.ConfigAuthLookup) (*project.Project, error) { @@ -184,7 +184,7 @@ func adjustContainerNames(m map[interface{}]interface{}) map[interface{}]interfa return m } -func newCoreServiceProject(cfg *config.CloudConfig, useNetwork bool) (*project.Project, error) { +func newCoreServiceProject(cfg *config.CloudConfig, useNetwork, loadConsole bool) (*project.Project, error) { environmentLookup := rosDocker.NewConfigEnvironment(cfg) authLookup := rosDocker.NewConfigAuthLookup(cfg) @@ -197,7 +197,7 @@ func newCoreServiceProject(cfg *config.CloudConfig, useNetwork bool) (*project.P p.AddListener(project.NewDefaultListener(p)) p.AddListener(projectEvents) - p.ReloadCallback = projectReload(p, &useNetwork, environmentLookup, authLookup) + p.ReloadCallback = projectReload(p, &useNetwork, loadConsole, environmentLookup, authLookup) go func() { for event := range projectEvents { diff --git a/compose/reload.go b/compose/reload.go index b2278664..616b605b 100644 --- a/compose/reload.go +++ b/compose/reload.go @@ -36,7 +36,7 @@ func LoadService(p *project.Project, cfg *config.CloudConfig, useNetwork bool, s return nil } -func projectReload(p *project.Project, useNetwork *bool, environmentLookup *docker.ConfigEnvironment, authLookup *docker.ConfigAuthLookup) func() error { +func projectReload(p *project.Project, useNetwork *bool, loadConsole bool, environmentLookup *docker.ConfigEnvironment, authLookup *docker.ConfigAuthLookup) func() error { enabled := map[interface{}]interface{}{} return func() error { cfg := config.LoadConfig() @@ -61,11 +61,12 @@ func projectReload(p *project.Project, useNetwork *bool, environmentLookup *dock enabled[service] = service } - if cfg.Rancher.Console != "" { - err := LoadService(p, cfg, *useNetwork, cfg.Rancher.Console) - if err != nil && err != network.ErrNoNetwork { - log.Error(err) - } + if !loadConsole || cfg.Rancher.Console == "" || cfg.Rancher.Console == "default" { + return nil + } + + if err := LoadService(p, cfg, *useNetwork, cfg.Rancher.Console); err != nil && err != network.ErrNoNetwork { + log.Error(err) } return nil diff --git a/init/sysinit.go b/init/sysinit.go index 6e50975c..0dfa96cb 100644 --- a/init/sysinit.go +++ b/init/sysinit.go @@ -94,7 +94,7 @@ func SysInit() error { _, err := config.ChainCfgFuncs(cfg, loadImages, func(cfg *config.CloudConfig) (*config.CloudConfig, error) { - p, err := compose.GetProject(cfg, false) + p, err := compose.GetProject(cfg, false, true) if err != nil { return cfg, err } diff --git a/os-config.tpl.yml b/os-config.tpl.yml index c31ba828..ad9a59e2 100644 --- a/os-config.tpl.yml +++ b/os-config.tpl.yml @@ -62,6 +62,7 @@ rancher: bootstrap_docker: args: [daemon, -s, overlay, -b, none, --restart=false, -g, /var/lib/system-docker, -G, root, -H, 'unix:///var/run/system-docker.sock', --userland-proxy=false] + console: default cloud_init: datasources: - configdrive:/media/config-2