示例#1
0
文件: weave.go 项目: pulcy/gluon
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)
}
示例#2
0
文件: consul.go 项目: pulcy/gluon
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)
}
示例#3
0
文件: rkt.go 项目: pulcy/gluon
func createService(serviceName string, deps service.ServiceDependencies, flags *service.ServiceFlags) (bool, error) {
	serviceTemplate := serviceTemplate(serviceName)
	servicePath := servicePath(serviceName)
	deps.Logger.Info("creating %s", servicePath)
	opts := struct{}{}
	changed, err := templates.Render(serviceTemplate, servicePath, opts, serviceFileMode)
	return changed, maskAny(err)
}
示例#4
0
文件: env.go 项目: pulcy/gluon
func createBashrc(deps service.ServiceDependencies, flags *service.ServiceFlags) error {
	deps.Logger.Info("creating %s", bashrcPath)
	os.Remove(bashrcPath)
	if _, err := templates.Render(bashrcTemplate, bashrcPath, nil, fileMode); err != nil {
		return maskAny(err)
	}

	return nil
}
示例#5
0
文件: docker.go 项目: pulcy/gluon
func createDockerService(deps service.ServiceDependencies, flags *service.ServiceFlags) (bool, error) {
	deps.Logger.Info("creating %s", servicePath)
	opts := struct {
		DockerIP string
	}{
		DockerIP: flags.Docker.DockerIP,
	}
	changed, err := templates.Render(serviceTemplate, servicePath, opts, serviceFileMode)
	return changed, maskAny(err)
}
示例#6
0
文件: fleet.go 项目: pulcy/gluon
func createSocket(deps service.ServiceDependencies, flags *service.ServiceFlags) (bool, error) {
	deps.Logger.Info("creating %s", socketPath)
	opts := struct {
		ClusterIP string
	}{
		ClusterIP: flags.Network.ClusterIP,
	}
	changed, err := templates.Render(socketTemplate, socketPath, opts, serviceFileMode)
	return changed, maskAny(err)
}
示例#7
0
文件: nomad.go 项目: pulcy/gluon
func createService(deps service.ServiceDependencies, flags *service.ServiceFlags) (bool, error) {
	deps.Logger.Info("creating %s", nomadServicePath)
	args := fmt.Sprintf("-bind=0.0.0.0 -data-dir=/opt/nomad/data -config=%s", nomadConfigPath)
	opts := struct {
		Flags string
	}{
		Flags: args,
	}
	changed, err := templates.Render(nomadServiceTmpl, nomadServicePath, opts, serviceFileMode)
	return changed, maskAny(err)
}
示例#8
0
文件: nomad.go 项目: pulcy/gluon
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)
}
示例#9
0
文件: binaries.go 项目: pulcy/gluon
func createBinariesMount(deps service.ServiceDependencies, flags *service.ServiceFlags) (bool, error) {
	deps.Logger.Info("creating %s", mountPath)
	opts := struct {
		MountPoint string
		LowerDir   string
		UpperDir   string
		WorkDir    string
	}{
		MountPoint: mountPoint,
		LowerDir:   mountPoint,
		UpperDir:   upperDir,
		WorkDir:    workDir,
	}
	changed, err := templates.Render(mountTemplate, mountPath, opts, fileMode)
	return changed, maskAny(err)
}
示例#10
0
文件: gluon.go 项目: pulcy/gluon
func createService(deps service.ServiceDependencies, flags *service.ServiceFlags) (bool, error) {
	deps.Logger.Info("creating %s", servicePath)
	opts := struct {
		GluonImage           string
		PrivateClusterDevice string
		DockerSubnet         string
		WeaveHostname        string
	}{
		GluonImage:           flags.GluonImage,
		PrivateClusterDevice: flags.Network.PrivateClusterDevice,
		DockerSubnet:         flags.Docker.DockerSubnet,
		WeaveHostname:        flags.Weave.Hostname,
	}
	changed, err := templates.Render(serviceTemplate, servicePath, opts, fileMode)
	return changed, maskAny(err)
}
示例#11
0
文件: sshd.go 项目: pulcy/gluon
func createSshdConfig(deps service.ServiceDependencies, flags *service.ServiceFlags) (bool, error) {
	deps.Logger.Info("creating %s", confPath)
	os.Remove(confPath)
	changed, err := templates.Render(confTemplate, confPath, nil, fileMode)
	return changed, maskAny(err)
}