func export(c *cli.Context) error { content, err := config.Export(c.Bool("private"), c.Bool("full")) if err != nil { log.Fatal(err) } output := c.String("output") if output == "" { fmt.Println(content) } else { err := util.WriteFileAtomic(output, []byte(content), 0400) if err != nil { log.Fatal(err) } } return nil }
func RunInit() error { os.Setenv("PATH", "/sbin:/usr/sbin:/usr/bin") if isInitrd() { log.Debug("Booting off an in-memory filesystem") // Magic setting to tell Docker to do switch_root and not pivot_root os.Setenv("DOCKER_RAMDISK", "true") } else { log.Debug("Booting off a persistent filesystem") } initFuncs := []config.CfgFunc{ func(c *config.CloudConfig) (*config.CloudConfig, error) { return c, dockerlaunch.PrepareFs(&mountConfig) }, mountOem, func(_ *config.CloudConfig) (*config.CloudConfig, error) { cfg := config.LoadConfig() if cfg.Rancher.Debug { cfgString, err := config.Export(false, true) if err != nil { log.WithFields(log.Fields{"err": err}).Error("Error serializing config") } else { log.Debugf("Config: %s", cfgString) } } return cfg, nil }, loadModules, tryMountAndBootstrap, func(_ *config.CloudConfig) (*config.CloudConfig, error) { return config.LoadConfig(), nil }, loadModules, func(c *config.CloudConfig) (*config.CloudConfig, error) { return c, dockerlaunch.PrepareFs(&mountConfig) }, func(c *config.CloudConfig) (*config.CloudConfig, error) { network.SetProxyEnvironmentVariables(c) return c, nil }, initializeSelinux, setupSharedRoot, sysInit, } cfg, err := config.ChainCfgFuncs(nil, initFuncs...) if err != nil { return err } launchConfig, args := getLaunchConfig(cfg, &cfg.Rancher.SystemDocker) launchConfig.Fork = !cfg.Rancher.SystemDocker.Exec log.Info("Launching System Docker") _, err = dockerlaunch.LaunchDocker(launchConfig, config.SYSTEM_DOCKER_BIN, args...) if err != nil { return err } return pidOne() }