Adding a bootstrap flag to allow single server raft

This commit is contained in:
Armon Dadgar 2013-12-24 16:48:07 -08:00
parent ee7469cac5
commit 9a2d3c144a
5 changed files with 25 additions and 1 deletions

View File

@ -111,6 +111,9 @@ func (a *Agent) consulConfig() *consul.Config {
if a.config.ServerAddr != "" {
base.RPCAddr = a.config.ServerAddr
}
if a.config.Bootstrap {
base.Bootstrap = true
}
// Setup the loggers
base.LogOutput = a.logOutput

View File

@ -49,7 +49,8 @@ func (c *Command) readConfig() *Config {
"address to bind RPC listener to")
cmdFlags.StringVar(&cmdConfig.DataDir, "data", "", "path to the data directory")
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 {
return nil
}

View File

@ -16,6 +16,10 @@ import (
// Some of this is configurable as CLI flags, but most must
// be set using a configuration file.
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 string
@ -120,6 +124,9 @@ func MergeConfig(a, b *Config) *Config {
var result Config = *a
// Copy the strings if they're set
if b.Bootstrap {
result.Bootstrap = true
}
if b.Datacenter != "" {
result.Datacenter = b.Datacenter
}

View File

@ -18,6 +18,11 @@ const (
// Config is used to configure the server
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 string
@ -69,5 +74,8 @@ func DefaultConfig() *Config {
conf.SerfLANConfig.MemberlistConfig.Port = DefaultLANSerfPort
conf.SerfWANConfig.MemberlistConfig.Port = DefaultWANSerfPort
// Disable shutdown on removal
conf.RaftConfig.ShutdownOnRemove = false
return conf
}

View File

@ -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
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
path := filepath.Join(s.config.DataDir, raftState)
if err := ensurePath(path, true); err != nil {