Browse Source

Merge branch 'master' of https://github.com/coreos/etcd into mod-lock

Ben Johnson 12 years ago
parent
commit
03571d3cda
3 changed files with 35 additions and 15 deletions
  1. 1 1
      README.md
  2. 14 14
      etcd.go
  3. 20 0
      server/config.go

+ 1 - 1
README.md

@@ -18,7 +18,7 @@ See [etcdctl][etcdctl] for a simple command line client.
 Or feel free to just use curl, as in the examples below.
 Or feel free to just use curl, as in the examples below.
 
 
 [raft]: https://github.com/coreos/go-raft
 [raft]: https://github.com/coreos/go-raft
-[etcdctl]: http://coreos.com/docs/etcdctl/
+[etcdctl]: http://github.com/coreos/etcdctl/
 
 
 ## Contact
 ## Contact
 
 

+ 14 - 14
etcd.go

@@ -52,24 +52,18 @@ func main() {
 		profile(config.CPUProfileFile)
 		profile(config.CPUProfileFile)
 	}
 	}
 
 
-	// Load info object.
-	info, err := config.Info()
-	if err != nil {
-		log.Fatal("info:", err)
+	// Only guess the machine name if there is no data dir specified
+	// because the info file will should have our name
+	if config.Name == "" && config.DataDir == "" {
+		config.NameFromHostname()
 	}
 	}
-	if info.Name == "" {
-		host, err := os.Hostname()
-		if err != nil || host == "" {
-			log.Fatal("Node name required and hostname not set. e.g. '-name=name'")
-		}
-		log.Warnf("Using hostname %s as the node name. You must ensure this name is unique among etcd nodes.", host)
-		info.Name = host
+
+	if config.DataDir == "" && config.Name != "" {
+		config.DataDirFromName()
 	}
 	}
 
 
-	// Setup a default directory based on the node name
 	if config.DataDir == "" {
 	if config.DataDir == "" {
-		config.DataDir = info.Name + ".etcd"
-		log.Warnf("Using the directory %s as the etcd configuration directory because a directory was not specified. ", config.DataDir)
+		log.Fatal("The data dir was not set and could not be guessed from machine name")
 	}
 	}
 
 
 	// Create data directory if it doesn't already exist.
 	// Create data directory if it doesn't already exist.
@@ -77,6 +71,12 @@ func main() {
 		log.Fatalf("Unable to create path: %s", err)
 		log.Fatalf("Unable to create path: %s", err)
 	}
 	}
 
 
+	// Load info object.
+	info, err := config.Info()
+	if err != nil {
+		log.Fatal("info:", err)
+	}
+
 	// Retrieve TLS configuration.
 	// Retrieve TLS configuration.
 	tlsConfig, err := info.EtcdTLS.Config()
 	tlsConfig, err := info.EtcdTLS.Config()
 	if err != nil {
 	if err != nil {

+ 20 - 0
server/config.go

@@ -13,6 +13,7 @@ import (
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
 
 
+	"github.com/coreos/etcd/log"
 	"github.com/BurntSushi/toml"
 	"github.com/BurntSushi/toml"
 )
 )
 
 
@@ -300,6 +301,25 @@ func (c *Config) LoadPeersFile() error {
 	return nil
 	return nil
 }
 }
 
 
+// DataDirFromName sets the data dir from a machine name and issue a warning
+// that etcd is guessing.
+func (c *Config) DataDirFromName() {
+	c.DataDir = c.Name + ".etcd"
+	log.Warnf("Using the directory %s as the etcd curation directory because a directory was not specified. ", c.DataDir)
+
+	return
+}
+
+// NameFromHostname sets the machine name from the hostname. This is to help
+// people get started without thinking up a name.
+func (c *Config) NameFromHostname() {
+	host, err := os.Hostname()
+	if err != nil && host == "" {
+		log.Fatal("Node name required and hostname not set. e.g. '-name=name'")
+	}
+	c.Name = host
+}
+
 // Reset removes all server configuration files.
 // Reset removes all server configuration files.
 func (c *Config) Reset() error {
 func (c *Config) Reset() error {
 	if err := os.RemoveAll(filepath.Join(c.DataDir, "info")); err != nil {
 	if err := os.RemoveAll(filepath.Join(c.DataDir, "info")); err != nil {