From 2db143cba0410259f495ccfe6eeb4c0c35fd0b2c Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Tue, 22 Sep 2015 12:40:21 -0700 Subject: [PATCH] command/agent: add bootstrap flags --- command/agent/command.go | 60 +++++++++++++++++++----- website/source/docs/agent/config.html.md | 3 ++ 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/command/agent/command.go b/command/agent/command.go index 3ac8aa12b..5ff91619b 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -67,6 +67,9 @@ func (c *Command) readConfig() *Config { flags.BoolVar(&cmdConfig.Server.Enabled, "server", false, "") flags.BoolVar(&cmdConfig.Client.Enabled, "client", false, "") + // Server-only options + flags.IntVar(&cmdConfig.Server.BootstrapExpect, "bootstrap-expect", 0, "") + // General options flags.Var((*sliceflag.StringFlag)(&configPath), "config", "config") flags.StringVar(&cmdConfig.BindAddr, "bind", "", "") @@ -121,17 +124,41 @@ func (c *Command) readConfig() *Config { // Merge any CLI options over config file options config = config.Merge(cmdConfig) - // Check that we have a data-dir if we are a server - if !dev && config.DataDir == "" { - c.Ui.Error("Must specify data directory") - return nil - } - // Set the version info config.Revision = c.Revision config.Version = c.Version config.VersionPrerelease = c.VersionPrerelease + if dev { + // Skip validation for dev mode + return config + } + + // Check that we have a data-dir + if config.DataDir == "" { + c.Ui.Error("Must specify data directory") + return nil + } + + // Check the bootstrap flags + if config.Server.Bootstrap || config.Server.BootstrapExpect > 0 { + if !config.Server.Enabled { + c.Ui.Error("Bootstrap requires server mode to be enabled") + return nil + } + } + if config.Server.Bootstrap && config.Server.BootstrapExpect > 0 { + c.Ui.Error("Bootstrap mode and BootstrapExpect are mutually exclusive") + return nil + } + if config.Server.BootstrapExpect == 1 { + config.Server.Bootstrap = true + config.Server.BootstrapExpect = 0 + } + if config.Server.Bootstrap { + c.Ui.Error("WARNING: Bootstrap mode enabled! Potentially unsafe operation.") + } + return config } @@ -549,25 +576,32 @@ General Options (clients and servers): Name of the region the Nomad agent will be a member of. By default this value is set to "global". -Role-Specific Options: - - -client - Enable client mode for the agent. Client mode enables a given node - to be evaluated for allocations. If client mode is not enabled, - no work will be scheduled to the agent. - -dev Start the agent in development mode. This enables a pre-configured dual-role agent (client + server) which is useful for developing or testing Nomad. No other configuration is required to start the agent in this mode. +Server Options: + -server Enable server mode for the agent. Agents in server mode are clustered together and handle the additional responsibility of leader election, data replication, and scheduling work onto eligible client nodes. + -bootstrap-expect= + Configures the expected number of servers nodes to wait for before + bootstrapping the cluster. Once servers have joined eachother, + Nomad initiates the bootstrap process. + +Client Options: + + -client + Enable client mode for the agent. Client mode enables a given node + to be evaluated for allocations. If client mode is not enabled, + no work will be scheduled to the agent. + Atlas Options: -atlas= diff --git a/website/source/docs/agent/config.html.md b/website/source/docs/agent/config.html.md index 44164cd29..cd6e27be8 100644 --- a/website/source/docs/agent/config.html.md +++ b/website/source/docs/agent/config.html.md @@ -236,6 +236,9 @@ A subset of the available Nomad agent configuration can optionally be passed in via CLI arguments. The `agent` command accepts the following arguments: * `-bind=
`: Equivalent to the [bind_addr](#bind_addr) config option. +* `-bootstrap`: Equivalent to the [bootstrap](#bootstrap) config option. +* `-bootstrap-expect=`: Equivalent to the + [bootstrap_expect](#bootstrap_expect) config option. * `-config=`: Specifies the path to a configuration file or a directory of configuration files to load. Can be specified multiple times. * `-data-dir=`: Equivalent to the [data_dir](#data_dir) config option.