當前位置: 首頁>>代碼示例>>Golang>>正文


Golang config.LoadConfig函數代碼示例

本文整理匯總了Golang中github.com/rancher/os/config.LoadConfig函數的典型用法代碼示例。如果您正苦於以下問題:Golang LoadConfig函數的具體用法?Golang LoadConfig怎麽用?Golang LoadConfig使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了LoadConfig函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: RunInit

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, err := config.LoadConfig()
			if err != nil {
				return cfg, err
			}

			if cfg.Rancher.Debug {
				cfgString, err := config.Dump(false, 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()
		},
		loadModules,
		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.DOCKER_BIN, args...)
	if err != nil {
		return err
	}
	return pidOne()
}
開發者ID:pombredanne,項目名稱:os-1,代碼行數:56,代碼來源:init.go

示例2: enable

func enable(c *cli.Context) {
	changed := false
	cfg, err := config.LoadConfig()
	if err != nil {
		logrus.Fatal(err)
	}

	for _, service := range c.Args() {
		if val, ok := cfg.Rancher.ServicesInclude[service]; !ok || !val {
			if strings.HasPrefix(service, "/") && !strings.HasPrefix(service, "/var/lib/rancher/conf") {
				logrus.Fatalf("ERROR: Service should be in path /var/lib/rancher/conf")
			}
			if _, err := compose.LoadServiceResource(service, true, cfg); err != nil {
				logrus.Fatalf("could not load service %s", service)
			}
			cfg.Rancher.ServicesInclude[service] = true
			changed = true
		}
	}

	if changed {
		if err := cfg.Save(); err != nil {
			logrus.Fatal(err)
		}
	}
}
開發者ID:pirater,項目名稱:os,代碼行數:26,代碼來源:service.go

示例3: Generate

func Generate(generateServer bool, outDir string, hostnames []string) error {
	cfg, err := config.LoadConfig()
	if err != nil {
		return err
	}

	if outDir == "" {
		return fmt.Errorf("out directory (-d, --dir) not specified")
	}
	caCertPath := filepath.Join(outDir, "ca.pem")
	caKeyPath := filepath.Join(outDir, "ca-key.pem")
	certPath := filepath.Join(outDir, "cert.pem")
	keyPath := filepath.Join(outDir, "key.pem")

	if generateServer {
		certPath = filepath.Join(outDir, "server-cert.pem")
		keyPath = filepath.Join(outDir, "server-key.pem")
	}

	if _, err := os.Stat(outDir); os.IsNotExist(err) {
		if err := os.MkdirAll(outDir, 0700); err != nil {
			return err
		}
	}

	if err := writeCaCerts(cfg, caCertPath, caKeyPath); err != nil {
		return err
	}

	return writeCerts(generateServer, hostnames, cfg, certPath, keyPath, caCertPath, caKeyPath)
}
開發者ID:Jdesk,項目名稱:os,代碼行數:31,代碼來源:tlsconf.go

示例4: Main

func Main() {
	cfg := config.LoadConfig()

	execID, resp, err := startDocker(cfg)
	if err != nil {
		log.Fatal(err)
	}

	process, err := getDockerProcess()
	if err != nil {
		log.Fatal(err)
	}

	handleTerm(process)

	// Wait for Docker daemon to exit
	io.Copy(ioutil.Discard, resp.Reader)
	resp.Close()

	client, err := rosDocker.NewSystemClient()
	if err != nil {
		log.Fatal(err)
	}

	state, err := client.ContainerExecInspect(context.Background(), execID)
	if err != nil {
		log.Fatal(err)
	}

	// Proxy exit code
	os.Exit(state.ExitCode)
}
開發者ID:coderjoe,項目名稱:os,代碼行數:32,代碼來源:main.go

示例5: enable

func enable(c *cli.Context) {
	cfg, err := config.LoadConfig()
	if err != nil {
		logrus.Fatal(err)
	}

	var enabledServices []string

	for _, service := range c.Args() {
		if val, ok := cfg.Rancher.ServicesInclude[service]; !ok || !val {
			if strings.HasPrefix(service, "/") && !strings.HasPrefix(service, "/var/lib/rancher/conf") {
				logrus.Fatalf("ERROR: Service should be in path /var/lib/rancher/conf")
			}

			cfg.Rancher.ServicesInclude[service] = true
			enabledServices = append(enabledServices, service)
		}
	}

	if len(enabledServices) > 0 {
		if err := compose.StageServices(cfg, enabledServices...); err != nil {
			logrus.Fatal(err)
		}

		if err := cfg.Save(); err != nil {
			logrus.Fatal(err)
		}
	}
}
開發者ID:carriercomm,項目名稱:os,代碼行數:29,代碼來源:service.go

示例6: runImport

func runImport(c *cli.Context) {
	var input io.ReadCloser
	var err error
	input = os.Stdin
	cfg, err := config.LoadConfig()

	if err != nil {
		log.Fatal(err)
	}

	inputFile := c.String("input")
	if inputFile != "" {
		input, err = os.Open(inputFile)
		if err != nil {
			log.Fatal(err)
		}
		defer input.Close()
	}

	bytes, err := ioutil.ReadAll(input)
	if err != nil {
		log.Fatal(err)
	}

	cfg, err = cfg.Import(bytes)
	if err != nil {
		log.Fatal(err)
	}

	if err := cfg.Save(); err != nil {
		log.Fatal(err)
	}
}
開發者ID:Jdesk,項目名稱:os,代碼行數:33,代碼來源:config.go

示例7: SysInit

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
}
開發者ID:liyimeng,項目名稱:os,代碼行數:25,代碼來源:sysinit.go

示例8: executeCloudConfig

func executeCloudConfig() error {
	cc, err := rancherConfig.LoadConfig()
	if err != nil {
		return err
	}

	if _, err := SetHostname(cc); err != nil {
		return err
	}

	if len(cc.SSHAuthorizedKeys) > 0 {
		authorizeSSHKeys("rancher", cc.SSHAuthorizedKeys, sshKeyName)
		authorizeSSHKeys("docker", cc.SSHAuthorizedKeys, sshKeyName)
	}

	for _, file := range cc.WriteFiles {
		f := system.File{File: file}
		fullPath, err := system.WriteFile(&f, "/")
		if err != nil {
			log.WithFields(log.Fields{"err": err, "path": fullPath}).Error("Error writing file")
			continue
		}
		log.Printf("Wrote file %s to filesystem", fullPath)
	}

	return nil
}
開發者ID:liyimeng,項目名稱:os,代碼行數:27,代碼來源:cloudinit.go

示例9: configGet

func configGet(c *cli.Context) {
	arg := c.Args().Get(0)
	if arg == "" {
		return
	}

	cfg, err := config.LoadConfig()
	if err != nil {
		log.WithFields(log.Fields{"err": err}).Fatal("config get: failed to load config")
	}

	val, err := cfg.Get(arg)
	if err != nil {
		log.WithFields(log.Fields{"cfg": cfg, "key": arg, "val": val, "err": err}).Fatal("config get: failed to retrieve value")
	}

	printYaml := false
	switch val.(type) {
	case []interface{}:
		printYaml = true
	case map[interface{}]interface{}:
		printYaml = true
	}

	if printYaml {
		bytes, err := yaml.Marshal(val)
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(string(bytes))
	} else {
		fmt.Println(val)
	}
}
開發者ID:Jdesk,項目名稱:os,代碼行數:34,代碼來源:config.go

示例10: envAction

func envAction(c *cli.Context) {
	cfg, err := config.LoadConfig()
	if err != nil {
		log.Fatal(err)
	}

	args := c.Args()
	if len(args) == 0 {
		return
	}
	osEnv := os.Environ()

	envMap := make(map[string]string, len(cfg.Rancher.Environment)+len(osEnv))
	for k, v := range cfg.Rancher.Environment {
		envMap[k] = v
	}
	for k, v := range util.KVPairs2Map(osEnv) {
		envMap[k] = v
	}

	if cmd, err := exec.LookPath(args[0]); err != nil {
		log.Fatal(err)
	} else {
		args[0] = cmd
	}
	if err := syscall.Exec(args[0], args, util.Map2KVPairs(envMap)); err != nil {
		log.Fatal(err)
	}
}
開發者ID:pirater,項目名稱:os,代碼行數:29,代碼來源:env.go

示例11: loadFromNetwork

func loadFromNetwork(location string) ([]byte, error) {
	bytes := cacheLookup(location)
	if bytes != nil {
		return bytes, nil
	}

	cfg := config.LoadConfig()
	SetProxyEnvironmentVariables(cfg)

	var err error
	for i := 0; i < 300; i++ {
		updateDNSCache()

		var resp *http.Response
		resp, err = http.Get(location)
		if err == nil {
			defer resp.Body.Close()
			if resp.StatusCode != http.StatusOK {
				return nil, fmt.Errorf("non-200 http response: %d", resp.StatusCode)
			}

			bytes, err := ioutil.ReadAll(resp.Body)
			if err != nil {
				return nil, err
			}

			cacheAdd(location, bytes)
			return bytes, nil
		}

		time.Sleep(100 * time.Millisecond)
	}

	return nil, err
}
開發者ID:coderjoe,項目名稱:os,代碼行數:35,代碼來源:network.go

示例12: Main

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)
	}
}
開發者ID:coderjoe,項目名稱:os,代碼行數:33,代碼來源:switch_console.go

示例13: getUpgradeUrl

func getUpgradeUrl() (string, error) {
	cfg, err := config.LoadConfig()
	if err != nil {
		return "", err
	}

	return cfg.Rancher.Upgrade.Url, nil
}
開發者ID:datawolf,項目名稱:os,代碼行數:8,代碼來源:os.go

示例14: Create

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)
}
開發者ID:carriercomm,項目名稱:os,代碼行數:8,代碼來源:service.go

示例15: mountOem

func mountOem(cfg *config.CloudConfig) (*config.CloudConfig, error) {
	if cfg == nil {
		cfg = config.LoadConfig()
	}
	if err := mountConfigured("oem", cfg.Rancher.State.OemDev, cfg.Rancher.State.OemFsType, config.OEM); err != nil {
		log.Debugf("Not mounting OEM: %v", err)
	} else {
		log.Infof("Mounted OEM: %s", cfg.Rancher.State.OemDev)
	}
	return cfg, nil
}
開發者ID:coderjoe,項目名稱:os,代碼行數:11,代碼來源:init.go


注:本文中的github.com/rancher/os/config.LoadConfig函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。