Adding a bootstrap flag to allow single server raft
This commit is contained in:
parent
fd9a44ba09
commit
69ed0ec184
|
@ -111,6 +111,9 @@ func (a *Agent) consulConfig() *consul.Config {
|
||||||
if a.config.ServerAddr != "" {
|
if a.config.ServerAddr != "" {
|
||||||
base.RPCAddr = a.config.ServerAddr
|
base.RPCAddr = a.config.ServerAddr
|
||||||
}
|
}
|
||||||
|
if a.config.Bootstrap {
|
||||||
|
base.Bootstrap = true
|
||||||
|
}
|
||||||
|
|
||||||
// Setup the loggers
|
// Setup the loggers
|
||||||
base.LogOutput = a.logOutput
|
base.LogOutput = a.logOutput
|
||||||
|
|
|
@ -49,7 +49,8 @@ func (c *Command) readConfig() *Config {
|
||||||
"address to bind RPC listener to")
|
"address to bind RPC listener to")
|
||||||
cmdFlags.StringVar(&cmdConfig.DataDir, "data", "", "path to the data directory")
|
cmdFlags.StringVar(&cmdConfig.DataDir, "data", "", "path to the data directory")
|
||||||
cmdFlags.StringVar(&cmdConfig.Datacenter, "dc", "", "node datacenter")
|
cmdFlags.StringVar(&cmdConfig.Datacenter, "dc", "", "node datacenter")
|
||||||
cmdFlags.BoolVar(&cmdConfig.Server, "server", false, "enable server mode")
|
cmdFlags.BoolVar(&cmdConfig.Server, "server", false, "run agent as server")
|
||||||
|
cmdFlags.BoolVar(&cmdConfig.Bootstrap, "bootstrap", false, "enable server bootstrap mode")
|
||||||
if err := cmdFlags.Parse(c.args); err != nil {
|
if err := cmdFlags.Parse(c.args); err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,10 @@ import (
|
||||||
// Some of this is configurable as CLI flags, but most must
|
// Some of this is configurable as CLI flags, but most must
|
||||||
// be set using a configuration file.
|
// be set using a configuration file.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
// Bootstrap is used to bring up the first Consul server, and
|
||||||
|
// permits that node to elect itself leader
|
||||||
|
Bootstrap bool
|
||||||
|
|
||||||
// Datacenter is the datacenter this node is in. Defaults to dc1
|
// Datacenter is the datacenter this node is in. Defaults to dc1
|
||||||
Datacenter string
|
Datacenter string
|
||||||
|
|
||||||
|
@ -120,6 +124,9 @@ func MergeConfig(a, b *Config) *Config {
|
||||||
var result Config = *a
|
var result Config = *a
|
||||||
|
|
||||||
// Copy the strings if they're set
|
// Copy the strings if they're set
|
||||||
|
if b.Bootstrap {
|
||||||
|
result.Bootstrap = true
|
||||||
|
}
|
||||||
if b.Datacenter != "" {
|
if b.Datacenter != "" {
|
||||||
result.Datacenter = b.Datacenter
|
result.Datacenter = b.Datacenter
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,11 @@ const (
|
||||||
|
|
||||||
// Config is used to configure the server
|
// Config is used to configure the server
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
// Bootstrap mode is used to bring up the first Consul server.
|
||||||
|
// It is required so that it can elect a leader without any
|
||||||
|
// other nodes being present
|
||||||
|
Bootstrap bool
|
||||||
|
|
||||||
// Datacenter is the datacenter this Consul server represents
|
// Datacenter is the datacenter this Consul server represents
|
||||||
Datacenter string
|
Datacenter string
|
||||||
|
|
||||||
|
@ -69,5 +74,8 @@ func DefaultConfig() *Config {
|
||||||
conf.SerfLANConfig.MemberlistConfig.Port = DefaultLANSerfPort
|
conf.SerfLANConfig.MemberlistConfig.Port = DefaultLANSerfPort
|
||||||
conf.SerfWANConfig.MemberlistConfig.Port = DefaultWANSerfPort
|
conf.SerfWANConfig.MemberlistConfig.Port = DefaultWANSerfPort
|
||||||
|
|
||||||
|
// Disable shutdown on removal
|
||||||
|
conf.RaftConfig.ShutdownOnRemove = false
|
||||||
|
|
||||||
return conf
|
return conf
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,6 +158,11 @@ func (s *Server) setupSerf(conf *serf.Config, ch chan serf.Event, path string) (
|
||||||
|
|
||||||
// setupRaft is used to setup and initialize Raft
|
// setupRaft is used to setup and initialize Raft
|
||||||
func (s *Server) setupRaft() error {
|
func (s *Server) setupRaft() error {
|
||||||
|
// If we are in bootstrap mode, enable a single node cluster
|
||||||
|
if s.config.Bootstrap {
|
||||||
|
s.config.RaftConfig.EnableSingleNode = true
|
||||||
|
}
|
||||||
|
|
||||||
// Create the base path
|
// Create the base path
|
||||||
path := filepath.Join(s.config.DataDir, raftState)
|
path := filepath.Join(s.config.DataDir, raftState)
|
||||||
if err := ensurePath(path, true); err != nil {
|
if err := ensurePath(path, true); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue