本文整理汇总了Golang中github.com/rancher/os/config.LoadConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang LoadConfig函数的具体用法?Golang LoadConfig怎么用?Golang LoadConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LoadConfig函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: Main
func Main() {
args := os.Args
if len(args) > 1 {
fmt.Println("call " + args[0] + " to load network config from cloud-config.yml")
return
}
os.Remove(NETWORK_DONE) // ignore error
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
hostname, _ := cloudinit.SetHostname(cfg) // ignore error
log.Infof("Network: hostname: '%s'", hostname)
if err := netconf.ApplyNetworkConfigs(&cfg.Rancher.Network); err != nil {
log.Error(err)
}
hostname, _ = cloudinit.SetHostname(cfg) // ignore error
log.Infof("Network: hostname: '%s' (from DHCP, if not set by cloud-config)", hostname)
if hostname != "" {
hosts, err := os.Open("/etc/hosts")
defer hosts.Close()
if err != nil {
log.Fatal(err)
}
lines := bufio.NewScanner(hosts)
hostsContent := ""
for lines.Scan() {
line := strings.TrimSpace(lines.Text())
fields := strings.Fields(line)
if len(fields) > 0 && fields[0] == "127.0.1.1" {
hostsContent += "127.0.1.1 " + hostname + "\n"
continue
}
hostsContent += line + "\n"
}
if err := ioutil.WriteFile("/etc/hosts", []byte(hostsContent), 0600); err != nil {
log.Error(err)
}
}
if cfg.Rancher.Network.Dns.Override {
log.WithFields(log.Fields{"nameservers": cfg.Rancher.Network.Dns.Nameservers}).Info("Override nameservers")
if _, err := resolvconf.Build("/etc/resolv.conf", cfg.Rancher.Network.Dns.Nameservers, cfg.Rancher.Network.Dns.Search, nil); err != nil {
log.Error(err)
}
}
if f, err := os.Create(NETWORK_DONE); err != nil {
log.Error(err)
} else {
f.Close()
}
sendTerm(WAIT_FOR_NETWORK)
select {}
}
开发者ID:pirater,项目名称:os,代码行数:53,代码来源:network.go
示例17: mountOem
func mountOem(cfg *config.CloudConfig) (*config.CloudConfig, error) {
if cfg == nil {
var err error
if cfg, err = config.LoadConfig(); err != nil {
return cfg, err
}
}
if err := mountConfigured("oem", cfg.Rancher.State.OemDev, cfg.Rancher.State.OemFsType, config.OEM); err != nil {
log.Infof("Not mounting OEM: %v", err)
}
return cfg, nil
}
开发者ID:pirater,项目名称:os,代码行数:12,代码来源:init.go
示例18: shouldRebuild
func (s *Service) shouldRebuild(ctx context.Context) (bool, error) {
containers, err := s.Containers(ctx)
if err != nil {
return false, err
}
cfg := config.LoadConfig()
for _, c := range containers {
outOfSync, err := c.(*docker.Container).OutOfSync(ctx, s.Service.Config().Image)
if err != nil {
return false, err
}
_, containerInfo, err := s.getContainer(ctx)
if err != nil {
return false, err
}
name := containerInfo.Name[1:]
origRebuildLabel := containerInfo.Config.Labels[config.REBUILD]
newRebuildLabel := s.Config().Labels[config.REBUILD]
rebuildLabelChanged := newRebuildLabel != origRebuildLabel
logrus.WithFields(logrus.Fields{
"origRebuildLabel": origRebuildLabel,
"newRebuildLabel": newRebuildLabel,
"rebuildLabelChanged": rebuildLabelChanged,
"outOfSync": outOfSync}).Debug("Rebuild values")
if newRebuildLabel == "always" {
return true, nil
}
if outOfSync {
if s.Name() == "console" {
if cfg.Rancher.ForceConsoleRebuild {
if err := config.Set("rancher.force_console_rebuild", false); err != nil {
return false, err
}
return true, nil
}
origConsoleLabel := containerInfo.Config.Labels[config.CONSOLE]
newConsoleLabel := s.Config().Labels[config.CONSOLE]
if newConsoleLabel != origConsoleLabel {
return true, nil
}
} else if rebuildLabelChanged || origRebuildLabel != "false" {
return true, nil
} else {
logrus.Warnf("%s needs rebuilding", name)
}
}
}
return false, nil
}
开发者ID:coderjoe,项目名称:os,代码行数:52,代码来源:service.go
示例19: Main
func Main() {
flags.Parse(os.Args[1:])
log.Infof("Running network: daemon=%v", daemon)
os.Remove(NETWORK_DONE) // ignore error
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
nameservers := cfg.Rancher.Network.Dns.Nameservers
search := cfg.Rancher.Network.Dns.Search
userSetDns := len(nameservers) > 0 || len(search) > 0
if !userSetDns {
nameservers = cfg.Rancher.DefaultNetwork.Dns.Nameservers
search = cfg.Rancher.DefaultNetwork.Dns.Search
}
if _, err := resolvconf.Build("/etc/resolv.conf", nameservers, search, nil); err != nil {
log.Error(err)
}
if err := hostname.SetHostnameFromCloudConfig(cfg); err != nil {
log.Error(err)
}
if err := netconf.ApplyNetworkConfigs(&cfg.Rancher.Network); err != nil {
log.Error(err)
}
userSetHostname := cfg.Hostname != ""
if err := netconf.RunDhcp(&cfg.Rancher.Network, !userSetHostname, !userSetDns); err != nil {
log.Error(err)
}
if err := hostname.SyncHostname(); err != nil {
log.Error(err)
}
if f, err := os.Create(NETWORK_DONE); err != nil {
log.Error(err)
} else {
f.Close()
}
sendTerm(WAIT_FOR_NETWORK)
if daemon {
select {}
}
}
开发者ID:carriercomm,项目名称:os,代码行数:51,代码来源:network.go
示例20: Main
func Main() {
args := os.Args
if len(args) > 1 {
fmt.Println("call " + args[0] + " to load network config from cloud-config.yml")
return
}
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}
if err := netconf.ApplyNetworkConfigs(&cfg.Rancher.Network); err != nil {
log.Fatal(err)
}
}
开发者ID:sysuwbs,项目名称:os,代码行数:14,代码来源:network.go
注:本文中的github.com/rancher/os/config.LoadConfig函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论