2014-03-18 20:00:41 +04:00
|
|
|
package initialize
|
2014-03-05 04:36:05 +04:00
|
|
|
|
|
|
|
import (
|
2014-03-18 02:09:59 +04:00
|
|
|
"fmt"
|
2014-03-05 04:36:05 +04:00
|
|
|
"os"
|
|
|
|
"path"
|
2014-03-18 02:09:59 +04:00
|
|
|
"strings"
|
2014-03-18 20:00:41 +04:00
|
|
|
|
|
|
|
"github.com/coreos/coreos-cloudinit/system"
|
2014-03-05 04:36:05 +04:00
|
|
|
)
|
|
|
|
|
2014-03-18 02:09:59 +04:00
|
|
|
type EtcdEnvironment map[string]string
|
|
|
|
|
|
|
|
func (ec EtcdEnvironment) String() (out string) {
|
|
|
|
public := os.Getenv("COREOS_PUBLIC_IPV4")
|
|
|
|
private := os.Getenv("COREOS_PRIVATE_IPV4")
|
|
|
|
|
|
|
|
out += "[Service]\n"
|
|
|
|
|
|
|
|
for key, val := range ec {
|
|
|
|
key = strings.ToUpper(key)
|
|
|
|
key = strings.Replace(key, "-", "_", -1)
|
|
|
|
|
|
|
|
if public != "" {
|
|
|
|
val = strings.Replace(val, "$public_ipv4", public, -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
if private != "" {
|
|
|
|
val = strings.Replace(val, "$private_ipv4", private, -1)
|
|
|
|
}
|
|
|
|
|
|
|
|
out += fmt.Sprintf("Environment=\"ETCD_%s=%s\"\n", key, val)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write an EtcdEnvironment to the appropriate path on disk for etcd.service
|
2014-03-18 20:00:41 +04:00
|
|
|
func WriteEtcdEnvironment(env EtcdEnvironment, root string) error {
|
|
|
|
file := system.File{
|
2014-03-18 21:36:34 +04:00
|
|
|
Path: path.Join(root, "run", "systemd", "system", "etcd.service.d", "20-cloudinit.conf"),
|
2014-03-18 20:00:41 +04:00
|
|
|
RawFilePermissions: "0644",
|
|
|
|
Content: env.String(),
|
2014-03-05 04:36:05 +04:00
|
|
|
}
|
|
|
|
|
2014-03-18 20:00:41 +04:00
|
|
|
return system.WriteFile(&file)
|
2014-03-05 04:36:05 +04:00
|
|
|
}
|