Пример #1
0
func RunInit() error {
	var cfg config.CloudConfig

	os.Setenv("PATH", "/sbin:/usr/sbin:/usr/bin")
	// Magic setting to tell Docker to do switch_root and not pivot_root
	os.Setenv("DOCKER_RAMDISK", "true")

	initFuncs := []config.InitFunc{
		func(cfg *config.CloudConfig) error {
			return dockerlaunch.PrepareFs(&mountConfig)
		},
		func(cfg *config.CloudConfig) error {
			newCfg, err := config.LoadConfig()
			if err == nil {
				newCfg, err = config.LoadConfig()
			}
			if err == nil {
				*cfg = *newCfg
			}

			if cfg.Rancher.Debug {
				cfgString, err := config.Dump(false, true)
				if err != nil {
					log.WithFields(log.Fields{"err": err}).Error("Error serializing config")
				} else {
					log.Debugf("Config: %s", cfgString)
				}
			}

			return err
		},
		loadModules,
		tryMountAndBootstrap,
		func(cfg *config.CloudConfig) error {
			return cfg.Reload()
		},
		loadModules,
		sysInit,
	}

	if err := config.RunInitFuncs(&cfg, initFuncs); err != nil {
		return err
	}

	launchConfig, args := getLaunchConfig(&cfg, &cfg.Rancher.SystemDocker)

	log.Info("Launching System Docker")
	_, err := dockerlaunch.LaunchDocker(launchConfig, config.DOCKER_BIN, args...)
	return err
}
Пример #2
0
func bootstrap(cfg *config.Config) error {
	log.Info("Starting bootstrap")
	c, err := startDocker(cfg)
	if err != nil {
		return err
	}

	initFuncs := []config.InitFunc{
		loadImages,
		runBootstrapContainers,
		autoformat,
	}

	defer stopDocker(c)

	return config.RunInitFuncs(cfg, initFuncs)
}
Пример #3
0
func SysInit() error {
	cfg, err := config.LoadConfig()
	if err != nil {
		return err
	}

	initFuncs := []config.InitFunc{
		loadImages,
		runContainers,
		func(cfg *config.Config) error {
			syscall.Sync()
			return nil
		},
		func(cfg *config.Config) error {
			log.Infof("RancherOS %s started", config.VERSION)
			return nil
		},
		tailConsole,
	}

	return config.RunInitFuncs(cfg, initFuncs)
}
Пример #4
0
func SysInit() error {
	cfg, err := config.LoadConfig()
	if err != nil {
		return err
	}

	initFuncs := []config.InitFunc{
		loadImages,
		func(cfg *config.CloudConfig) error {
			return compose.RunServices(cfg)
		},
		func(cfg *config.CloudConfig) error {
			syscall.Sync()
			return nil
		},
		func(cfg *config.CloudConfig) error {
			log.Infof("RancherOS %s started", config.VERSION)
			return nil
		},
	}

	return config.RunInitFuncs(cfg, initFuncs)
}
Пример #5
0
func RunInit() error {
	var cfg config.Config

	os.Setenv("PATH", "/sbin:/usr/sbin:/usr/bin")
	os.Setenv("DOCKER_RAMDISK", "true")

	initFuncs := []config.InitFunc{
		func(cfg *config.Config) error {
			return createDirs(dirs...)
		},
		func(cfg *config.Config) error {
			log.Info("Setting up mounts")
			return createMounts(mounts...)
		},
		func(cfg *config.Config) error {
			newCfg, err := config.LoadConfig()
			if err == nil {
				newCfg, err = config.LoadConfig()
			}
			if err == nil {
				*cfg = *newCfg
			}

			if cfg.Debug {
				cfgString, _ := config.Dump(false, true)
				if cfgString != "" {
					log.Debugf("Config: %s", cfgString)
				}
			}

			return err
		},
		mountCgroups,
		func(cfg *config.Config) error {
			return createSymlinks(cfg, symlinks)
		},
		createGroups,
		extractModules,
		loadModules,
		setResolvConf,
		setupSystemBridge,
		bootstrap,
		mountState,
		func(cfg *config.Config) error {
			return cfg.Reload()
		},
		loadModules,
		setResolvConf,
		func(cfg *config.Config) error {
			return createDirs(postDirs...)
		},
		func(cfg *config.Config) error {
			return createMounts(postMounts...)
		},
		touchSocket,
		// Disable R/O root write now to support updating modules
		//remountRo,
		sysInit,
	}

	if err := config.RunInitFuncs(&cfg, initFuncs); err != nil {
		return err
	}

	return execDocker(&cfg)
}