diff --git a/CHANGELOG.md b/CHANGELOG.md index 830f81fa6d7..fbe377a07d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - [#2376](https://github.com/influxdb/influxdb/pull/2376): Encode all types of integers. Thanks @jtakkala. - [#2376](https://github.com/influxdb/influxdb/pull/2376): Add shard path to existing diags value. Fix issue #2369. - [#2386](https://github.com/influxdb/influxdb/pull/2386): Fix shard datanodes stats getting appended too many times +- [#2393](https://github.com/influxdb/influxdb/pull/2393): Fix default hostname for connecting to cluster. ## v0.9.0-rc26 [04-21-2015] diff --git a/cmd/influxd/config.go b/cmd/influxd/config.go index 65587bc6dcd..c40dc701eb0 100644 --- a/cmd/influxd/config.go +++ b/cmd/influxd/config.go @@ -31,6 +31,12 @@ const ( // DefaultAPIReadTimeout represents the duration before an API request times out. DefaultAPIReadTimeout = 5 * time.Second + // DefaultHostName represents the default host name to use if it is never provided + DefaultHostName = "localhost" + + // DefaultBindAddress represents the bind address to use if none is specified + DefaultBindAddress = "0.0.0.0" + // DefaultClusterPort represents the default port the cluster runs ons. DefaultClusterPort = 8086 @@ -227,6 +233,8 @@ type Config struct { // NewConfig returns an instance of Config with reasonable defaults. func NewConfig() *Config { c := &Config{} + c.Hostname = DefaultHostName + c.BindAddress = DefaultBindAddress c.Port = DefaultClusterPort c.Data.Enabled = DefaultDataEnabled diff --git a/cmd/influxd/run.go b/cmd/influxd/run.go index 1c99abca885..26d7af8748e 100644 --- a/cmd/influxd/run.go +++ b/cmd/influxd/run.go @@ -44,6 +44,8 @@ type Node struct { DataNode *influxdb.Server raftLog *raft.Log + hostname string + adminServer *admin.Server clusterListener net.Listener // The cluster TCP listener apiListener net.Listener // The API TCP listener @@ -56,15 +58,13 @@ func (s *Node) ClusterAddr() net.Addr { } func (s *Node) ClusterURL() *url.URL { - h, p, e := net.SplitHostPort(s.ClusterAddr().String()) + // Find out which port the cluster started on + _, p, e := net.SplitHostPort(s.ClusterAddr().String()) if e != nil { panic(e) } - if h == "::" || h == "" { - h = "localhost" - } - h = net.JoinHostPort(h, p) + h := net.JoinHostPort(s.hostname, p) return &url.URL{ Scheme: "http", Host: h, @@ -189,34 +189,31 @@ func (s *Node) closeClusterListener() error { return err } -func (cmd *RunCommand) ParseConfig(path, hostname string) error { - var err error - +func (cmd *RunCommand) ParseConfig(path string) error { // Parse configuration file from disk. if path != "" { + var err error cmd.config, err = ParseConfigFile(path) - if err != nil { return fmt.Errorf("error parsing configuration %s - %s\n", path, err) } - // Override config properties. - if hostname != "" { - cmd.config.Hostname = hostname + log.Printf("using configuration at: %s\n", path) + } else { + var err error + cmd.config, err = NewTestConfig() + + if err != nil { + return fmt.Errorf("error parsing default config: %s\n", err) } - log.Printf("using configuration at: %s\n", path) - return nil + log.Println("no configuration provided, using default settings") } - cmd.config, err = NewTestConfig() - if err != nil { - return fmt.Errorf("error parsing default config: %s\n", err) - } // Override config properties. - if hostname != "" { - cmd.config.Hostname = hostname + if cmd.hostname != "" { + cmd.config.Hostname = cmd.hostname } - log.Println("no configuration provided, using default settings") + cmd.node.hostname = cmd.config.Hostname return nil } @@ -249,7 +246,7 @@ func (cmd *RunCommand) Run(args ...string) error { log.Printf("GOMAXPROCS set to %d", runtime.GOMAXPROCS(0)) // Parse config - if err := cmd.ParseConfig(configPath, hostname); err != nil { + if err := cmd.ParseConfig(configPath); err != nil { log.Fatal(err) } @@ -321,7 +318,7 @@ func (cmd *RunCommand) Open(config *Config, join string) *Node { if err := cmd.node.openClusterListener(cmd.config.ClusterAddr(), h); err != nil { log.Fatalf("Cluster server failed to listen on %s. %s ", cmd.config.ClusterAddr(), err) } - log.Printf("Cluster server listening on %s", cmd.node.ClusterURL().String()) + log.Printf("Cluster server listening on %s", cmd.node.ClusterAddr().String()) // Open broker & raft log, initialize or join as necessary. if cmd.config.Broker.Enabled {