func newCoreServiceProject(cfg *config.CloudConfig, useNetwork, loadConsole bool) (*project.Project, error) { environmentLookup := rosDocker.NewConfigEnvironment(cfg) authLookup := rosDocker.NewConfigAuthLookup(cfg) p, err := newProject("os", cfg, environmentLookup, authLookup) if err != nil { return nil, err } projectEvents := make(chan events.Event) p.AddListener(project.NewDefaultListener(p)) p.AddListener(projectEvents) p.ReloadCallback = projectReload(p, &useNetwork, loadConsole, environmentLookup, authLookup) go func() { for event := range projectEvents { if event.EventType == events.ContainerStarted && event.ServiceName == "ntp" { useNetwork = true } } }() err = p.ReloadCallback() if err != nil { log.Errorf("Failed to reload os: %v", err) return nil, err } return p, nil }
func newCoreServiceProject(cfg *config.CloudConfig, network bool) (*project.Project, error) { projectEvents := make(chan project.Event) enabled := map[interface{}]interface{}{} p, err := newProject("os", cfg) if err != nil { return nil, err } p.AddListener(project.NewDefaultListener(p)) p.AddListener(projectEvents) p.ReloadCallback = func() error { var err error cfg, err = config.LoadConfig() if err != nil { return err } enabled = addServices(p, enabled, cfg.Rancher.Services) for service, serviceEnabled := range cfg.Rancher.ServicesInclude { if _, ok := enabled[service]; ok || !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 } m := map[interface{}]interface{}{} if err := yaml.Unmarshal(bytes, &m); err != nil { log.Errorf("Failed to parse YAML configuration: %s : %v", service, err) continue } bytes, err = yaml.Marshal(adjustContainerNames(config.StringifyValues(m))) if err != nil { log.Errorf("Failed to marshal YAML configuration: %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.EventType == project.EventContainerStarted && 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 }
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 }