Fixup default hostname and config
parent
c0df09d544
commit
1696db1c40
|
@ -28,6 +28,15 @@ import (
|
|||
"github.com/influxdb/influxdb/tsdb"
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultBindAddress is the default address for raft, cluster, snapshot, etc..
|
||||
DefaultBindAddress = ":8088"
|
||||
|
||||
// DefaultHostname is the default hostname used if we are unable to determine
|
||||
// the hostname from the system
|
||||
DefaultHostname = "localhost"
|
||||
)
|
||||
|
||||
// Config represents the configuration format for the influxd binary.
|
||||
type Config struct {
|
||||
Meta *meta.Config `toml:"meta"`
|
||||
|
@ -55,10 +64,6 @@ type Config struct {
|
|||
|
||||
// BindAddress is the address that all TCP services use (Raft, Snapshot, Cluster, etc.)
|
||||
BindAddress string `toml:"bind-address"`
|
||||
|
||||
// Hostname is the resolvable name for other servers in
|
||||
// the cluster to reach this server
|
||||
Hostname string `toml:"hostname"`
|
||||
}
|
||||
|
||||
// NewConfig returns an instance of Config with reasonable defaults.
|
||||
|
@ -79,6 +84,7 @@ func NewConfig() *Config {
|
|||
c.ContinuousQuery = continuous_querier.NewConfig()
|
||||
c.Retention = retention.NewConfig()
|
||||
c.HintedHandoff = hh.NewConfig()
|
||||
c.BindAddress = DefaultBindAddress
|
||||
|
||||
return c
|
||||
}
|
||||
|
|
|
@ -109,6 +109,8 @@ func NewServer(c *Config, buildInfo *BuildInfo) (*Server, error) {
|
|||
if dir == "" {
|
||||
dir = c.Meta.Dir
|
||||
}
|
||||
|
||||
// load the node information
|
||||
node, err := influxdb.NewNode(dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -117,7 +119,7 @@ func NewServer(c *Config, buildInfo *BuildInfo) (*Server, error) {
|
|||
// In 0.10.0 bind-address got moved to the top level. Check
|
||||
// The old location to keep things backwards compatible
|
||||
bind := c.BindAddress
|
||||
if bind == "" {
|
||||
if c.Meta.BindAddress != "" {
|
||||
bind = c.Meta.BindAddress
|
||||
}
|
||||
|
||||
|
@ -125,16 +127,11 @@ func NewServer(c *Config, buildInfo *BuildInfo) (*Server, error) {
|
|||
return nil, fmt.Errorf("must run as either meta node or data node or both")
|
||||
}
|
||||
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to determine hostname: %v", err)
|
||||
}
|
||||
|
||||
httpBindAddress, err := defaultHost(hostname, c.HTTPD.BindAddress)
|
||||
httpBindAddress, err := defaultHost(DefaultHostname, c.HTTPD.BindAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tcpBindAddress, err := defaultHost(hostname, bind)
|
||||
tcpBindAddress, err := defaultHost(DefaultHostname, bind)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package meta
|
|||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/influxdb/influxdb/toml"
|
||||
|
@ -49,10 +48,6 @@ type Config struct {
|
|||
Enabled bool `toml:"enabled"`
|
||||
Dir string `toml:"dir"`
|
||||
|
||||
// hostname used if bind addresses do not specify an IP or hostname. We look
|
||||
// this up once to avoid resolving it too frequently.
|
||||
hostname string
|
||||
|
||||
// this is deprecated. Should use the address from run/config.go
|
||||
BindAddress string `toml:"bind-address"`
|
||||
|
||||
|
@ -78,16 +73,7 @@ type Config struct {
|
|||
|
||||
// NewConfig builds a new configuration with default values.
|
||||
func NewConfig() *Config {
|
||||
// Lookup our hostname and fall back to our default "localhost" if that
|
||||
// fails for any reason. The hostname needs to be resolvable by remote
|
||||
// cluster nodes.
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
hostname = DefaultHostname
|
||||
}
|
||||
|
||||
return &Config{
|
||||
hostname: hostname,
|
||||
Enabled: true, // enabled by default
|
||||
BindAddress: DefaultRaftBindAddress,
|
||||
HTTPBindAddress: DefaultHTTPBindAddress,
|
||||
|
@ -116,7 +102,7 @@ func (c *Config) defaultHost(addr string) string {
|
|||
}
|
||||
|
||||
if host == "" {
|
||||
return net.JoinHostPort(c.hostname, port)
|
||||
return net.JoinHostPort(DefaultHostname, port)
|
||||
}
|
||||
return addr
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue