func Main() { if len(os.Args) != 2 { log.Fatal("Must specify exactly one existing container") } newConsole := os.Args[1] cfg := config.LoadConfig() project, err := compose.GetProject(cfg, true, false) if err != nil { log.Fatal(err) } if newConsole != "default" { if err = compose.LoadService(project, cfg, true, newConsole); err != nil { log.Fatal(err) } } 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 { log.Fatal(err) } if err = project.Restart(context.Background(), 10, "docker"); err != nil { log.Errorf("Failed to restart Docker: %v", err) } }
func SysInit() error { cfg, err := config.LoadConfig() if err != nil { return err } _, err = config.ChainCfgFuncs(cfg, loadImages, func(cfg *config.CloudConfig) (*config.CloudConfig, error) { p, err := compose.GetProject(cfg, false) if err != nil { return cfg, err } return cfg, p.Up() }, func(cfg *config.CloudConfig) (*config.CloudConfig, error) { syscall.Sync() return cfg, nil }, func(cfg *config.CloudConfig) (*config.CloudConfig, error) { log.Infof("RancherOS %s started", config.VERSION) return cfg, nil }) return err }
func (p *projectFactory) Create(c *cli.Context) (*project.Project, error) { cfg, err := config.LoadConfig() if err != nil { return nil, err } return compose.GetProject(cfg, true) }
func enter(cfg *config.CloudConfig) error { context := cfg.Rancher.Docker.StorageContext if context == "" { context = DEFAULT_STORAGE_CONTEXT } log.Infof("Starting Docker in context: %s", context) p, err := compose.GetProject(cfg, true) if err != nil { return err } pid, err := waitForPid(context, p) if err != nil { return err } log.Infof("%s PID %d", context, pid) return runNsenter(pid) }
func startDocker(cfg *config.CloudConfig) (string, types.HijackedResponse, error) { storageContext := cfg.Rancher.Docker.StorageContext if storageContext == "" { storageContext = DEFAULT_STORAGE_CONTEXT } log.Infof("Starting Docker in context: %s", storageContext) p, err := compose.GetProject(cfg, true, false) if err != nil { return "", types.HijackedResponse{}, err } pid, err := waitForPid(storageContext, p) if err != nil { return "", types.HijackedResponse{}, err } log.Infof("%s PID %d", storageContext, pid) client, err := rosDocker.NewSystemClient() if err != nil { return "", types.HijackedResponse{}, err } if err := os.Remove(DOCKER_PID_FILE); err != nil && !os.IsNotExist(err) { return "", types.HijackedResponse{}, err } dockerCfg := cfg.Rancher.Docker args := dockerCfg.FullArgs() log.Debugf("User Docker args: %v", args) if dockerCfg.TLS { if err := writeCerts(cfg); err != nil { return "", types.HijackedResponse{}, err } } cmd := []string{"env"} log.Info(dockerCfg.AppendEnv()) cmd = append(cmd, dockerCfg.AppendEnv()...) cmd = append(cmd, DOCKER_COMMAND) cmd = append(cmd, args...) log.Infof("Running %v", cmd) resp, err := client.ContainerExecCreate(context.Background(), types.ExecConfig{ Container: storageContext, Privileged: true, AttachStderr: true, AttachStdout: true, Cmd: cmd, }) if err != nil { return "", types.HijackedResponse{}, err } attachResp, err := client.ContainerExecAttach(context.Background(), resp.ID, types.ExecConfig{ Detach: false, AttachStderr: true, AttachStdout: true, }) if err != nil { return "", types.HijackedResponse{}, err } return resp.ID, attachResp, nil }