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 }
func newCoreServiceProject(cfg *config.CloudConfig) (*project.Project, error) { network := false projectEvents := make(chan project.ProjectEvent) enabled := make(map[string]string) p, err := newProject("os", cfg) if err != nil { return nil, err } p.AddListener(project.NewDefaultListener(p)) p.AddListener(projectEvents) p.ReloadCallback = func() error { err := cfg.Reload() if err != nil { return err } addServices(p, cfg, enabled, cfg.Rancher.Services) for service, serviceEnabled := range cfg.Rancher.ServicesInclude { if enabled[service] != "" || !serviceEnabled { continue } bytes, err := LoadServiceResource(service, network, cfg) if err != nil { if err == util.ErrNoNetwork { log.Debugf("Can not load %s, networking not enabled", service) } else { log.Errorf("Failed to load %s : %v", service, err) } continue } err = p.Load(bytes) if err != nil { log.Errorf("Failed to load %s : %v", service, err) continue } enabled[service] = service } return nil } go func() { for event := range projectEvents { if event.Event == project.CONTAINER_STARTED && event.ServiceName == "network" { network = true } } }() err = p.ReloadCallback() if err != nil { log.Errorf("Failed to reload os: %v", err) return nil, err } return p, nil }