mirror of
https://github.com/rancher/os.git
synced 2025-08-02 07:24:28 +00:00
Support switching to the default console
This commit is contained in:
parent
7f7d8765ca
commit
3153c28e86
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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{
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user