open-consul/consul/config.go

74 lines
1.8 KiB
Go
Raw Normal View History

2013-12-06 23:43:07 +00:00
package consul
import (
"github.com/hashicorp/memberlist"
"github.com/hashicorp/raft"
"github.com/hashicorp/serf/serf"
"io"
"os"
)
const (
2013-12-20 23:33:13 +00:00
DefaultDC = "dc1"
2013-12-07 00:35:13 +00:00
DefaultRPCAddr = "0.0.0.0:8300"
2013-12-20 23:33:13 +00:00
DefaultRPCPort = 8000
2013-12-09 22:22:23 +00:00
DefaultLANSerfPort = 8301
DefaultWANSerfPort = 8302
2013-12-06 23:43:07 +00:00
)
// Config is used to configure the server
type Config struct {
// Datacenter is the datacenter this Consul server represents
Datacenter string
// DataDir is the directory to store our state in
DataDir string
// Node name is the name we use to advertise. Defaults to hostname.
NodeName string
// RaftConfig is the configuration used for Raft in the local DC
RaftConfig *raft.Config
2013-12-07 00:35:13 +00:00
// RPCAddr is the RPC address used by Consul. This should be reachable
// by the WAN and LAN
RPCAddr string
2013-12-07 01:18:09 +00:00
// SerfLANConfig is the configuration for the intra-dc serf
SerfLANConfig *serf.Config
2013-12-06 23:43:07 +00:00
2013-12-07 01:18:09 +00:00
// SerfWANConfig is the configuration for the cross-dc serf
SerfWANConfig *serf.Config
2013-12-06 23:43:07 +00:00
// LogOutput is the location to write logs to. If this is not set,
// logs will go to stderr.
LogOutput io.Writer
}
// DefaultConfig is used to return a sane default configuration
func DefaultConfig() *Config {
hostname, err := os.Hostname()
if err != nil {
panic(err)
}
conf := &Config{
2013-12-20 23:33:13 +00:00
Datacenter: DefaultDC,
2013-12-07 01:18:09 +00:00
NodeName: hostname,
RPCAddr: DefaultRPCAddr,
RaftConfig: raft.DefaultConfig(),
SerfLANConfig: serf.DefaultConfig(),
SerfWANConfig: serf.DefaultConfig(),
2013-12-06 23:43:07 +00:00
}
2013-12-07 01:18:09 +00:00
// WAN Serf should use the WAN timing, since we are using it
2013-12-06 23:43:07 +00:00
// to communicate between DC's
2013-12-07 01:18:09 +00:00
conf.SerfWANConfig.MemberlistConfig = memberlist.DefaultWANConfig()
2013-12-06 23:43:07 +00:00
// Ensure we don't have port conflicts
2013-12-07 01:18:09 +00:00
conf.SerfLANConfig.MemberlistConfig.Port = DefaultLANSerfPort
conf.SerfWANConfig.MemberlistConfig.Port = DefaultWANSerfPort
2013-12-06 23:43:07 +00:00
return conf
}