Ejemplo n.º 1
0
Archivo: weave.go Proyecto: 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)
}
Ejemplo n.º 2
0
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)
}
Ejemplo n.º 3
0
Archivo: rkt.go Proyecto: 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)
}
Ejemplo n.º 4
0
Archivo: env.go Proyecto: 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
}
Ejemplo n.º 5
0
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)
}
Ejemplo n.º 6
0
Archivo: fleet.go Proyecto: 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)
}
Ejemplo n.º 7
0
Archivo: nomad.go Proyecto: 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)
}
Ejemplo n.º 8
0
Archivo: nomad.go Proyecto: 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)
}
Ejemplo n.º 9
0
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)
}
Ejemplo n.º 10
0
Archivo: gluon.go Proyecto: 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)
}
Ejemplo n.º 11
0
Archivo: sshd.go Proyecto: 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)
}