• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang service.ServiceFlags类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/pulcy/gluon/service.ServiceFlags的典型用法代码示例。如果您正苦于以下问题:Golang ServiceFlags类的具体用法?Golang ServiceFlags怎么用?Golang ServiceFlags使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ServiceFlags类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: createService

func createService(deps service.ServiceDependencies, flags *service.ServiceFlags) (bool, error) {
	deps.Logger.Info("creating %s", weaveServicePath)
	members, err := flags.GetClusterMembers(deps.Logger)
	if err != nil {
		return false, maskAny(err)
	}
	var peers []string
	for _, m := range members {
		peers = append(peers, m.PrivateHostIP)
	}
	name, err := getPeerName(deps, flags)
	if err != nil {
		return false, maskAny(err)
	}
	opts := struct {
		Seed     string
		Peers    string
		Name     string
		Hostname string
	}{
		Seed:     flags.Weave.Seed,
		Peers:    strings.Join(peers, " "),
		Name:     name,
		Hostname: flags.Weave.Hostname,
	}
	changed, err := templates.Render(weaveServiceTmpl, weaveServicePath, opts, serviceFileMode)
	return changed, maskAny(err)
}
开发者ID:pulcy,项目名称:gluon,代码行数:28,代码来源:weave.go


示例2: createFleetConf

func createFleetConf(deps service.ServiceDependencies, flags *service.ServiceFlags) (bool, error) {
	proxy, err := isEtcdProxy(deps, flags)
	if err != nil {
		return false, maskAny(err)
	}

	members, err := flags.GetClusterMembers(deps.Logger)
	if err != nil {
		deps.Logger.Warning("GetClusterMembers failed: %v", err)
	}
	etcdServers := []string{}
	for _, cm := range members {
		if !cm.EtcdProxy {
			etcdServers = append(etcdServers, fmt.Sprintf("http://%s:2379", cm.ClusterIP))
		}
	}

	lines := []string{
		"[Service]",
		fmt.Sprintf("Environment=FLEET_METADATA=%s", flags.Fleet.Metadata),
		fmt.Sprintf("Environment=FLEET_ETCD_SERVERS=%s", strings.Join(etcdServers, ",")),
		fmt.Sprintf("Environment=FLEET_PUBLIC_IP=%s", flags.Network.ClusterIP),
		fmt.Sprintf("Environment=FLEET_AGENT_TTL=%v", flags.Fleet.AgentTTL),
		fmt.Sprintf("Environment=FLEET_DISABLE_ENGINE=%v", proxy || flags.Fleet.DisableEngine),
		fmt.Sprintf("Environment=FLEET_DISABLE_WATCHES=%v", flags.Fleet.DisableWatches),
		fmt.Sprintf("Environment=FLEET_ENGINE_RECONCILE_INTERVAL=%d", flags.Fleet.EngineReconcileInterval),
		fmt.Sprintf("Environment=FLEET_TOKEN_LIMIT=%d", flags.Fleet.TokenLimit),
	}

	changed, err := util.UpdateFile(confPath, []byte(strings.Join(lines, "\n")), configFileMode)
	return changed, maskAny(err)
}
开发者ID:pulcy,项目名称:gluon,代码行数:32,代码来源:fleet.go


示例3: Setup

func (t *gluonService) Setup(deps service.ServiceDependencies, flags *service.ServiceFlags) error {
	if err := flags.SetupDefaults(deps.Logger); err != nil {
		return maskAny(err)
	}
	if flags.Docker.DockerSubnet == "" {
		return errgo.New("docker-subnet is missing")
	}

	changedFlags, err := flags.Save()
	if err != nil {
		return maskAny(err)
	}

	changedService, err := createService(deps, flags)
	if err != nil {
		return maskAny(err)
	}

	if flags.Force || changedFlags || changedService {
		if err := os.Remove(gluonPath); err != nil {
			if !os.IsNotExist(err) {
				return maskAny(err)
			}
		}

		if err := deps.Systemd.Reload(); err != nil {
			return maskAny(err)
		}
		if err := deps.Systemd.Enable(serviceName); err != nil {
			return maskAny(err)
		}
	}

	return nil
}
开发者ID:pulcy,项目名称:gluon,代码行数:35,代码来源:gluon.go


示例4: createService

func createService(deps service.ServiceDependencies, flags *service.ServiceFlags) (bool, error) {
	deps.Logger.Info("creating %s", consulServicePath)
	members, err := flags.GetClusterMembers(deps.Logger)
	if err != nil {
		return false, maskAny(err)
	}
	var join []string
	bootstrapExpect := 0
	for _, m := range members {
		if !m.EtcdProxy {
			bootstrapExpect++
			if m.ClusterIP != flags.Network.ClusterIP {
				join = append(join, fmt.Sprintf("-retry-join %s", m.ClusterIP))
			}
		}
	}
	srv, err := isServer(members, flags)
	if err != nil {
		return false, maskAny(err)
	}
	args := fmt.Sprintf("-advertise=%s %s -client=0.0.0.0 -data-dir=/opt/consul/data", flags.Network.ClusterIP, strings.Join(join, " "))
	if srv {
		args = fmt.Sprintf("-server -bootstrap-expect=%d %s", bootstrapExpect, args)
	}
	opts := struct {
		Flags string
	}{
		Flags: args,
	}
	changed, err := templates.Render(consulServiceTmpl, consulServicePath, opts, serviceFileMode)
	return changed, maskAny(err)
}
开发者ID:pulcy,项目名称:gluon,代码行数:32,代码来源:consul.go


示例5: createEtcdConfig

func createEtcdConfig(deps service.ServiceDependencies, flags *service.ServiceFlags) (etcdConfig, error) {
	if flags.Network.ClusterIP == "" {
		return etcdConfig{}, maskAny(fmt.Errorf("ClusterIP empty"))
	}

	members, err := flags.GetClusterMembers(deps.Logger)
	if err != nil {
		deps.Logger.Warning("GetClusterMembers failed: %v", err)
	}

	result := etcdConfig{
		ClusterIP: flags.Network.ClusterIP,
	}
	initialCluster := []string{}
	endpoints := []string{}
	hosts := []string{}
	clientPort := 2379
	result.ClusterState = flags.Etcd.ClusterState
	if result.ClusterState == "" {
		result.ClusterState = "new"
	}
	memberIndex := 0
	for index, cm := range members {
		if !cm.EtcdProxy {
			initialCluster = append(initialCluster, fmt.Sprintf("%s=http://%s:2380", cm.MachineID, cm.ClusterIP))
			endpoints = append(endpoints, fmt.Sprintf("http://%s:%d", cm.ClusterIP, clientPort))
			hosts = append(hosts, cm.ClusterIP)
		}
		if cm.ClusterIP == flags.Network.ClusterIP {
			result.Name = cm.MachineID
			result.IsProxy = cm.EtcdProxy
			result.PrivateHostIP = cm.PrivateHostIP
			if cm.EtcdProxy {
				memberIndex = index
			} else {
				memberIndex = len(hosts) - 1
			}
		}
	}

	result.ListenPeerURLs = fmt.Sprintf("https://%s:2381,http://%s:2380", result.PrivateHostIP, flags.Network.ClusterIP)
	result.AdvertisePeerURLs = fmt.Sprintf("https://%s:2381,http://%s:2380", result.PrivateHostIP, flags.Network.ClusterIP)
	result.ListenClientURLs = fmt.Sprintf("http://0.0.0.0:%d,http://0.0.0.0:4001", clientPort)
	result.AdvertiseClientURLs = fmt.Sprintf("http://%s:%d,http://%s:4001", flags.Network.ClusterIP, clientPort, flags.Network.ClusterIP)

	result.InitialCluster = strings.Join(initialCluster, ",")
	result.Endpoints = strings.Join(endpoints, ",")
	result.Host = hosts[memberIndex%len(hosts)]
	result.Port = strconv.Itoa(clientPort)

	return result, nil

}
开发者ID:pulcy,项目名称:gluon,代码行数:53,代码来源:etcd2.go


示例6: isEtcdProxy

func isEtcdProxy(deps service.ServiceDependencies, flags *service.ServiceFlags) (bool, error) {
	members, err := flags.GetClusterMembers(deps.Logger)
	if err != nil {
		return false, maskAny(err)
	}
	for _, member := range members {
		if member.ClusterIP == flags.Network.ClusterIP {
			return member.EtcdProxy, nil
		}
	}

	return false, nil
}
开发者ID:pulcy,项目名称:gluon,代码行数:13,代码来源:fleet.go


示例7: createConfig

func createConfig(deps service.ServiceDependencies, flags *service.ServiceFlags) (bool, error) {
	deps.Logger.Info("creating %s", nomadConfigPath)
	members, err := flags.GetClusterMembers(deps.Logger)
	if err != nil {
		return false, maskAny(err)
	}
	srv, err := isServer(members, flags)
	if err != nil {
		return false, maskAny(err)
	}
	vaultEnv, err := readVaultEnv()
	if err != nil {
		return false, maskAny(err)
	}
	vaultAddress := vaultEnv["VAULT_ADDR"]
	vaultCAFile := vaultEnv["VAULT_CACERT"]
	bootstrapExpect := 0
	for _, m := range members {
		if !m.EtcdProxy {
			bootstrapExpect++
		}
	}
	opts := struct {
		AdvertiseIP     string
		ConsulAddress   string
		MetaLines       []string
		IsServer        bool
		BootstrapExpect int
		HasVault        bool
		VaultAddress    string
		VaultCAFile     string
	}{
		AdvertiseIP:     flags.Network.ClusterIP,
		ConsulAddress:   fmt.Sprintf("%s:8500", flags.Network.ClusterIP),
		IsServer:        srv,
		BootstrapExpect: bootstrapExpect,
		HasVault:        false && vaultAddress != "" && vaultCAFile != "", // Vault token is also needed before we can enable
		VaultAddress:    vaultAddress,
		VaultCAFile:     vaultCAFile,
	}
	metaParts := strings.Split(flags.Fleet.Metadata, ",")
	for _, meta := range metaParts {
		kv := strings.SplitN(meta, "=", 2)
		if len(kv) == 2 {
			opts.MetaLines = append(opts.MetaLines, fmt.Sprintf("\"%s\" = \"%s\"", kv[0], kv[1]))
		}
	}

	changed, err := templates.Render(nomadConfigTmpl, nomadConfigPath, opts, configFileMode)
	return changed, maskAny(err)
}
开发者ID:pulcy,项目名称:gluon,代码行数:51,代码来源:nomad.go


示例8: createNoProxy

// createNoProxy creates the value for the no_proxy environment variable.
func createNoProxy(deps service.ServiceDependencies, flags *service.ServiceFlags) (string, error) {
	members, err := flags.GetClusterMembers(deps.Logger)
	if err != nil {
		return "", maskAny(err)
	}
	list := []string{".local", ".private"}
	for _, cm := range members {
		list = append(list, cm.ClusterIP)
		if cm.ClusterIP != cm.PrivateHostIP {
			list = append(list, cm.PrivateHostIP)
		}
	}
	return strings.Join(list, ","), nil
}
开发者ID:pulcy,项目名称:gluon,代码行数:15,代码来源:proxy.go


示例9: getPeerName

func getPeerName(deps service.ServiceDependencies, flags *service.ServiceFlags) (string, error) {
	members, err := flags.GetClusterMembers(deps.Logger)
	if err != nil {
		return "", maskAny(err)
	}
	for _, member := range members {
		if member.ClusterIP == flags.Network.ClusterIP {
			name, err := util.WeaveNameFromMachineID(member.MachineID)
			if err != nil {
				return "", maskAny(err)
			}
			return name, nil
		}
	}

	return "", nil
}
开发者ID:pulcy,项目名称:gluon,代码行数:17,代码来源:weave.go



注:本文中的github.com/pulcy/gluon/service.ServiceFlags类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang jobs.Task类代码示例发布时间:2022-05-28
下一篇:
Golang purell.NormalizeURLString函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap