2015-08-16 01:34:47 +00:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
2015-08-16 01:54:41 +00:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
2015-08-16 20:54:49 +00:00
|
|
|
"io"
|
2016-02-12 00:05:31 +00:00
|
|
|
"log"
|
2015-08-16 20:54:49 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
2015-08-16 21:34:38 +00:00
|
|
|
"path/filepath"
|
2015-12-03 07:22:18 +00:00
|
|
|
"reflect"
|
2015-08-16 21:34:38 +00:00
|
|
|
"sort"
|
|
|
|
"strconv"
|
2015-08-16 01:34:47 +00:00
|
|
|
"strings"
|
2015-08-16 20:54:49 +00:00
|
|
|
"syscall"
|
2015-08-16 01:54:41 +00:00
|
|
|
"time"
|
2015-08-16 01:34:47 +00:00
|
|
|
|
2015-08-16 01:54:41 +00:00
|
|
|
"github.com/armon/go-metrics"
|
2016-07-22 16:33:10 +00:00
|
|
|
"github.com/armon/go-metrics/circonus"
|
2016-10-15 08:49:33 +00:00
|
|
|
"github.com/armon/go-metrics/datadog"
|
2016-05-03 07:15:29 +00:00
|
|
|
"github.com/hashicorp/consul/lib"
|
2015-08-16 21:34:38 +00:00
|
|
|
"github.com/hashicorp/go-checkpoint"
|
2015-08-16 20:54:49 +00:00
|
|
|
"github.com/hashicorp/go-syslog"
|
|
|
|
"github.com/hashicorp/logutils"
|
2016-10-11 01:04:39 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/flag-helpers"
|
2015-08-23 23:57:54 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/gated-writer"
|
2016-09-01 22:41:07 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs/config"
|
2016-06-01 20:34:59 +00:00
|
|
|
"github.com/hashicorp/scada-client/scada"
|
2015-08-16 01:34:47 +00:00
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
)
|
|
|
|
|
2015-08-16 20:54:49 +00:00
|
|
|
// gracefulTimeout controls how long we wait before forcefully terminating
|
|
|
|
const gracefulTimeout = 5 * time.Second
|
|
|
|
|
2015-08-16 21:34:38 +00:00
|
|
|
// Command is a Command implementation that runs a Nomad agent.
|
2015-08-16 01:34:47 +00:00
|
|
|
// The command will not end unless a shutdown message is sent on the
|
|
|
|
// ShutdownCh. If two messages are sent on the ShutdownCh it will forcibly
|
|
|
|
// exit.
|
|
|
|
type Command struct {
|
|
|
|
Revision string
|
|
|
|
Version string
|
|
|
|
VersionPrerelease string
|
|
|
|
Ui cli.Ui
|
|
|
|
ShutdownCh <-chan struct{}
|
2015-08-16 01:54:41 +00:00
|
|
|
|
2015-12-09 23:50:18 +00:00
|
|
|
args []string
|
|
|
|
agent *Agent
|
|
|
|
httpServer *HTTPServer
|
|
|
|
logFilter *logutils.LevelFilter
|
|
|
|
logOutput io.Writer
|
2015-12-09 15:57:54 +00:00
|
|
|
retryJoinErrCh chan struct{}
|
2015-09-14 22:33:08 +00:00
|
|
|
|
|
|
|
scadaProvider *scada.Provider
|
|
|
|
scadaHttp *HTTPServer
|
2015-08-16 01:54:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Command) readConfig() *Config {
|
|
|
|
var dev bool
|
|
|
|
var configPath []string
|
2015-10-02 00:19:52 +00:00
|
|
|
var servers string
|
|
|
|
var meta []string
|
2015-09-22 03:38:43 +00:00
|
|
|
|
2015-09-22 17:44:31 +00:00
|
|
|
// Make a new, empty config.
|
|
|
|
cmdConfig := &Config{
|
2016-05-23 18:09:31 +00:00
|
|
|
Atlas: &AtlasConfig{},
|
|
|
|
Client: &ClientConfig{},
|
|
|
|
Ports: &Ports{},
|
|
|
|
Server: &ServerConfig{},
|
2016-09-01 22:41:07 +00:00
|
|
|
Vault: &config.VaultConfig{},
|
2015-09-22 17:44:31 +00:00
|
|
|
}
|
2015-09-22 03:38:43 +00:00
|
|
|
|
2015-08-16 01:54:41 +00:00
|
|
|
flags := flag.NewFlagSet("agent", flag.ContinueOnError)
|
|
|
|
flags.Usage = func() { c.Ui.Error(c.Help()) }
|
2015-09-22 04:37:55 +00:00
|
|
|
|
|
|
|
// Role options
|
2015-09-22 03:38:43 +00:00
|
|
|
flags.BoolVar(&dev, "dev", false, "")
|
|
|
|
flags.BoolVar(&cmdConfig.Server.Enabled, "server", false, "")
|
|
|
|
flags.BoolVar(&cmdConfig.Client.Enabled, "client", false, "")
|
2015-09-22 04:37:55 +00:00
|
|
|
|
2015-09-22 19:40:21 +00:00
|
|
|
// Server-only options
|
|
|
|
flags.IntVar(&cmdConfig.Server.BootstrapExpect, "bootstrap-expect", 0, "")
|
2015-12-02 19:55:29 +00:00
|
|
|
flags.BoolVar(&cmdConfig.Server.RejoinAfterLeave, "rejoin", false, "")
|
2016-10-11 01:04:39 +00:00
|
|
|
flags.Var((*flaghelper.StringFlag)(&cmdConfig.Server.StartJoin), "join", "")
|
|
|
|
flags.Var((*flaghelper.StringFlag)(&cmdConfig.Server.RetryJoin), "retry-join", "")
|
2015-12-02 19:55:29 +00:00
|
|
|
flags.IntVar(&cmdConfig.Server.RetryMaxAttempts, "retry-max", 0, "")
|
|
|
|
flags.StringVar(&cmdConfig.Server.RetryInterval, "retry-interval", "", "")
|
2016-10-17 17:48:04 +00:00
|
|
|
flags.StringVar(&cmdConfig.Server.EncryptKey, "encrypt", "", "gossip encryption key")
|
2015-09-22 19:40:21 +00:00
|
|
|
|
2015-10-01 23:46:42 +00:00
|
|
|
// Client-only options
|
|
|
|
flags.StringVar(&cmdConfig.Client.StateDir, "state-dir", "", "")
|
|
|
|
flags.StringVar(&cmdConfig.Client.AllocDir, "alloc-dir", "", "")
|
|
|
|
flags.StringVar(&cmdConfig.Client.NodeClass, "node-class", "", "")
|
|
|
|
flags.StringVar(&servers, "servers", "", "")
|
2016-10-11 01:04:39 +00:00
|
|
|
flags.Var((*flaghelper.StringFlag)(&meta), "meta", "")
|
2015-10-03 00:32:11 +00:00
|
|
|
flags.StringVar(&cmdConfig.Client.NetworkInterface, "network-interface", "", "")
|
|
|
|
flags.IntVar(&cmdConfig.Client.NetworkSpeed, "network-speed", 0, "")
|
2015-10-01 23:46:42 +00:00
|
|
|
|
2015-09-22 04:37:55 +00:00
|
|
|
// General options
|
2016-10-11 01:04:39 +00:00
|
|
|
flags.Var((*flaghelper.StringFlag)(&configPath), "config", "config")
|
2015-09-22 04:37:55 +00:00
|
|
|
flags.StringVar(&cmdConfig.BindAddr, "bind", "", "")
|
|
|
|
flags.StringVar(&cmdConfig.Region, "region", "", "")
|
2015-09-22 03:38:43 +00:00
|
|
|
flags.StringVar(&cmdConfig.DataDir, "data-dir", "", "")
|
2015-09-22 04:37:55 +00:00
|
|
|
flags.StringVar(&cmdConfig.Datacenter, "dc", "", "")
|
2015-09-22 22:23:30 +00:00
|
|
|
flags.StringVar(&cmdConfig.LogLevel, "log-level", "", "")
|
2015-09-22 04:37:55 +00:00
|
|
|
flags.StringVar(&cmdConfig.NodeName, "node", "", "")
|
|
|
|
|
|
|
|
// Atlas options
|
|
|
|
flags.StringVar(&cmdConfig.Atlas.Infrastructure, "atlas", "", "")
|
|
|
|
flags.BoolVar(&cmdConfig.Atlas.Join, "atlas-join", false, "")
|
|
|
|
flags.StringVar(&cmdConfig.Atlas.Token, "atlas-token", "", "")
|
2015-09-22 03:38:43 +00:00
|
|
|
|
2016-09-01 22:41:07 +00:00
|
|
|
// Vault options
|
2016-10-11 01:04:39 +00:00
|
|
|
flags.Var((flaghelper.FuncBoolVar)(func(b bool) error {
|
|
|
|
cmdConfig.Vault.Enabled = &b
|
|
|
|
return nil
|
|
|
|
}), "vault-enabled", "")
|
|
|
|
flags.Var((flaghelper.FuncBoolVar)(func(b bool) error {
|
|
|
|
cmdConfig.Vault.AllowUnauthenticated = &b
|
|
|
|
return nil
|
|
|
|
}), "vault-allow-unauthenticated", "")
|
2016-09-01 22:41:07 +00:00
|
|
|
flags.StringVar(&cmdConfig.Vault.Token, "vault-token", "", "")
|
|
|
|
flags.StringVar(&cmdConfig.Vault.Addr, "vault-address", "", "")
|
|
|
|
|
2015-08-16 01:54:41 +00:00
|
|
|
if err := flags.Parse(c.args); err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-10-01 23:46:42 +00:00
|
|
|
// Split the servers.
|
|
|
|
if servers != "" {
|
|
|
|
cmdConfig.Client.Servers = strings.Split(servers, ",")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the meta flags.
|
2015-10-02 00:21:32 +00:00
|
|
|
metaLength := len(meta)
|
|
|
|
if metaLength != 0 {
|
|
|
|
cmdConfig.Client.Meta = make(map[string]string, metaLength)
|
2015-10-01 23:46:42 +00:00
|
|
|
for _, kv := range meta {
|
2015-10-02 00:19:52 +00:00
|
|
|
parts := strings.SplitN(kv, "=", 2)
|
2015-10-01 23:46:42 +00:00
|
|
|
if len(parts) != 2 {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error parsing Client.Meta value: %v", kv))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdConfig.Client.Meta[parts[0]] = parts[1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-16 01:54:41 +00:00
|
|
|
// Load the configuration
|
|
|
|
var config *Config
|
|
|
|
if dev {
|
|
|
|
config = DevConfig()
|
2015-08-16 20:54:49 +00:00
|
|
|
} else {
|
|
|
|
config = DefaultConfig()
|
2015-08-16 01:54:41 +00:00
|
|
|
}
|
|
|
|
for _, path := range configPath {
|
|
|
|
current, err := LoadConfig(path)
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf(
|
|
|
|
"Error loading configuration from %s: %s", path, err))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-12-03 07:22:18 +00:00
|
|
|
// The user asked us to load some config here but we didn't find any,
|
|
|
|
// so we'll complain but continue.
|
|
|
|
if current == nil || reflect.DeepEqual(current, &Config{}) {
|
|
|
|
c.Ui.Warn(fmt.Sprintf("No configuration loaded from %s", path))
|
|
|
|
}
|
|
|
|
|
2015-08-16 01:54:41 +00:00
|
|
|
if config == nil {
|
|
|
|
config = current
|
|
|
|
} else {
|
|
|
|
config = config.Merge(current)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-16 21:34:38 +00:00
|
|
|
// Ensure the sub-structs at least exist
|
2015-09-22 04:37:55 +00:00
|
|
|
if config.Atlas == nil {
|
|
|
|
config.Atlas = &AtlasConfig{}
|
|
|
|
}
|
2015-08-16 21:34:38 +00:00
|
|
|
if config.Client == nil {
|
|
|
|
config.Client = &ClientConfig{}
|
|
|
|
}
|
|
|
|
if config.Server == nil {
|
|
|
|
config.Server = &ServerConfig{}
|
|
|
|
}
|
2015-08-16 22:10:11 +00:00
|
|
|
|
2015-09-22 03:38:43 +00:00
|
|
|
// Merge any CLI options over config file options
|
|
|
|
config = config.Merge(cmdConfig)
|
|
|
|
|
2015-08-16 22:10:11 +00:00
|
|
|
// Set the version info
|
|
|
|
config.Revision = c.Revision
|
|
|
|
config.Version = c.Version
|
|
|
|
config.VersionPrerelease = c.VersionPrerelease
|
|
|
|
|
2015-09-22 19:40:21 +00:00
|
|
|
if dev {
|
|
|
|
// Skip validation for dev mode
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
2016-10-17 17:48:04 +00:00
|
|
|
if config.Server.EncryptKey != "" {
|
|
|
|
if _, err := config.Server.EncryptBytes(); err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Invalid encryption key: %s", err))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
keyfile := filepath.Join(config.DataDir, serfKeyring)
|
|
|
|
if _, err := os.Stat(keyfile); err == nil {
|
|
|
|
c.Ui.Error("WARNING: keyring exists but -encrypt given, using keyring")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-18 00:33:09 +00:00
|
|
|
// Parse the RetryInterval.
|
|
|
|
dur, err := time.ParseDuration(config.Server.RetryInterval)
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error parsing retry interval: %s", err))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
config.Server.retryInterval = dur
|
2016-05-25 05:30:10 +00:00
|
|
|
|
2015-10-02 00:27:36 +00:00
|
|
|
// Check that the server is running in at least one mode.
|
|
|
|
if !(config.Server.Enabled || config.Client.Enabled) {
|
2015-10-01 23:46:42 +00:00
|
|
|
c.Ui.Error("Must specify either server, client or dev mode for the agent.")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-12-22 19:14:41 +00:00
|
|
|
// Verify the paths are absolute.
|
|
|
|
dirs := map[string]string{
|
|
|
|
"data-dir": config.DataDir,
|
|
|
|
"alloc-dir": config.Client.AllocDir,
|
|
|
|
"state-dir": config.Client.StateDir,
|
|
|
|
}
|
|
|
|
for k, dir := range dirs {
|
|
|
|
if dir == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if !filepath.IsAbs(dir) {
|
|
|
|
c.Ui.Error(fmt.Sprintf("%s must be given as an absolute path: got %v", k, dir))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 23:46:42 +00:00
|
|
|
// Ensure that we have the directories we neet to run.
|
|
|
|
if config.Server.Enabled && config.DataDir == "" {
|
2015-09-22 19:40:21 +00:00
|
|
|
c.Ui.Error("Must specify data directory")
|
|
|
|
return nil
|
2015-10-02 00:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The config is valid if the top-level data-dir is set or if both
|
|
|
|
// alloc-dir and state-dir are set.
|
|
|
|
if config.Client.Enabled && config.DataDir == "" {
|
2015-10-01 23:46:42 +00:00
|
|
|
if config.Client.AllocDir == "" || config.Client.StateDir == "" {
|
|
|
|
c.Ui.Error("Must specify both the state and alloc dir if data-dir is omitted.")
|
|
|
|
return nil
|
|
|
|
}
|
2015-09-22 19:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check the bootstrap flags
|
2015-09-22 21:25:43 +00:00
|
|
|
if config.Server.BootstrapExpect > 0 && !config.Server.Enabled {
|
|
|
|
c.Ui.Error("Bootstrap requires server mode to be enabled")
|
2015-09-22 19:40:21 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if config.Server.BootstrapExpect == 1 {
|
|
|
|
c.Ui.Error("WARNING: Bootstrap mode enabled! Potentially unsafe operation.")
|
|
|
|
}
|
|
|
|
|
2015-08-16 01:54:41 +00:00
|
|
|
return config
|
2015-08-16 01:34:47 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 20:54:49 +00:00
|
|
|
// setupLoggers is used to setup the logGate, logWriter, and our logOutput
|
2015-08-23 23:57:54 +00:00
|
|
|
func (c *Command) setupLoggers(config *Config) (*gatedwriter.Writer, *logWriter, io.Writer) {
|
2015-08-16 20:54:49 +00:00
|
|
|
// Setup logging. First create the gated log writer, which will
|
|
|
|
// store logs until we're ready to show them. Then create the level
|
|
|
|
// filter, filtering logs of the specified level.
|
2015-08-23 23:57:54 +00:00
|
|
|
logGate := &gatedwriter.Writer{
|
2015-08-16 20:54:49 +00:00
|
|
|
Writer: &cli.UiWriter{Ui: c.Ui},
|
|
|
|
}
|
|
|
|
|
|
|
|
c.logFilter = LevelFilter()
|
|
|
|
c.logFilter.MinLevel = logutils.LogLevel(strings.ToUpper(config.LogLevel))
|
|
|
|
c.logFilter.Writer = logGate
|
|
|
|
if !ValidateLevelFilter(c.logFilter.MinLevel, c.logFilter) {
|
|
|
|
c.Ui.Error(fmt.Sprintf(
|
|
|
|
"Invalid log level: %s. Valid log levels are: %v",
|
|
|
|
c.logFilter.MinLevel, c.logFilter.Levels))
|
|
|
|
return nil, nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if syslog is enabled
|
|
|
|
var syslog io.Writer
|
|
|
|
if config.EnableSyslog {
|
2015-08-16 21:34:38 +00:00
|
|
|
l, err := gsyslog.NewLogger(gsyslog.LOG_NOTICE, config.SyslogFacility, "nomad")
|
2015-08-16 20:54:49 +00:00
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Syslog setup failed: %v", err))
|
|
|
|
return nil, nil, nil
|
|
|
|
}
|
|
|
|
syslog = &SyslogWrapper{l, c.logFilter}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a log writer, and wrap a logOutput around it
|
|
|
|
logWriter := NewLogWriter(512)
|
|
|
|
var logOutput io.Writer
|
|
|
|
if syslog != nil {
|
|
|
|
logOutput = io.MultiWriter(c.logFilter, logWriter, syslog)
|
|
|
|
} else {
|
|
|
|
logOutput = io.MultiWriter(c.logFilter, logWriter)
|
|
|
|
}
|
|
|
|
c.logOutput = logOutput
|
2016-02-12 00:05:31 +00:00
|
|
|
log.SetOutput(logOutput)
|
2015-08-16 20:54:49 +00:00
|
|
|
return logGate, logWriter, logOutput
|
|
|
|
}
|
|
|
|
|
2015-08-16 21:34:38 +00:00
|
|
|
// setupAgent is used to start the agent and various interfaces
|
|
|
|
func (c *Command) setupAgent(config *Config, logOutput io.Writer) error {
|
|
|
|
c.Ui.Output("Starting Nomad agent...")
|
|
|
|
agent, err := NewAgent(config, logOutput)
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error starting agent: %s", err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
c.agent = agent
|
|
|
|
|
2015-09-14 22:33:08 +00:00
|
|
|
// Enable the SCADA integration
|
|
|
|
if err := c.setupSCADA(config); err != nil {
|
|
|
|
agent.Shutdown()
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error starting SCADA: %s", err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup the HTTP server
|
2015-08-24 00:50:33 +00:00
|
|
|
http, err := NewHTTPServer(agent, config, logOutput)
|
|
|
|
if err != nil {
|
|
|
|
agent.Shutdown()
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error starting http server: %s", err))
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
c.httpServer = http
|
|
|
|
|
2015-08-16 21:34:38 +00:00
|
|
|
// Setup update checking
|
|
|
|
if !config.DisableUpdateCheck {
|
|
|
|
version := config.Version
|
|
|
|
if config.VersionPrerelease != "" {
|
|
|
|
version += fmt.Sprintf("-%s", config.VersionPrerelease)
|
|
|
|
}
|
|
|
|
updateParams := &checkpoint.CheckParams{
|
|
|
|
Product: "nomad",
|
|
|
|
Version: version,
|
|
|
|
}
|
|
|
|
if !config.DisableAnonymousSignature {
|
|
|
|
updateParams.SignatureFile = filepath.Join(config.DataDir, "checkpoint-signature")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Schedule a periodic check with expected interval of 24 hours
|
|
|
|
checkpoint.CheckInterval(updateParams, 24*time.Hour, c.checkpointResults)
|
|
|
|
|
|
|
|
// Do an immediate check within the next 30 seconds
|
|
|
|
go func() {
|
2016-05-03 07:15:29 +00:00
|
|
|
time.Sleep(lib.RandomStagger(30 * time.Second))
|
2015-08-16 21:34:38 +00:00
|
|
|
c.checkpointResults(checkpoint.Check(updateParams))
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// checkpointResults is used to handler periodic results from our update checker
|
|
|
|
func (c *Command) checkpointResults(results *checkpoint.CheckResponse, err error) {
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Failed to check for updates: %v", err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if results.Outdated {
|
2016-05-05 06:56:37 +00:00
|
|
|
versionStr := c.Version
|
|
|
|
if c.VersionPrerelease != "" {
|
|
|
|
versionStr += fmt.Sprintf("-%s", c.VersionPrerelease)
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Ui.Error(fmt.Sprintf("Newer Nomad version available: %s (currently running: %s)", results.CurrentVersion, versionStr))
|
2015-08-16 21:34:38 +00:00
|
|
|
}
|
|
|
|
for _, alert := range results.Alerts {
|
|
|
|
switch alert.Level {
|
|
|
|
case "info":
|
|
|
|
c.Ui.Info(fmt.Sprintf("Bulletin [%s]: %s (%s)", alert.Level, alert.Message, alert.URL))
|
|
|
|
default:
|
|
|
|
c.Ui.Error(fmt.Sprintf("Bulletin [%s]: %s (%s)", alert.Level, alert.Message, alert.URL))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-16 01:34:47 +00:00
|
|
|
func (c *Command) Run(args []string) int {
|
|
|
|
c.Ui = &cli.PrefixedUi{
|
|
|
|
OutputPrefix: "==> ",
|
|
|
|
InfoPrefix: " ",
|
|
|
|
ErrorPrefix: "==> ",
|
|
|
|
Ui: c.Ui,
|
|
|
|
}
|
2015-08-16 01:54:41 +00:00
|
|
|
|
|
|
|
// Parse our configs
|
|
|
|
c.args = args
|
|
|
|
config := c.readConfig()
|
|
|
|
if config == nil {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2015-08-16 20:54:49 +00:00
|
|
|
// Setup the log outputs
|
2015-08-16 21:34:38 +00:00
|
|
|
logGate, _, logOutput := c.setupLoggers(config)
|
2015-08-16 20:54:49 +00:00
|
|
|
if logGate == nil {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2015-12-05 00:52:17 +00:00
|
|
|
// Log config files
|
2015-12-15 01:46:52 +00:00
|
|
|
if len(config.Files) > 0 {
|
2015-12-09 23:50:18 +00:00
|
|
|
c.Ui.Info(fmt.Sprintf("Loaded configuration from %s", strings.Join(config.Files, ", ")))
|
|
|
|
} else {
|
|
|
|
c.Ui.Info("No configuration files loaded")
|
|
|
|
}
|
2015-12-05 00:52:17 +00:00
|
|
|
|
2015-08-16 01:54:41 +00:00
|
|
|
// Initialize the telemetry
|
2016-09-11 07:46:05 +00:00
|
|
|
if err := c.setupTelemetry(config); err != nil {
|
2015-08-16 01:54:41 +00:00
|
|
|
c.Ui.Error(fmt.Sprintf("Error initializing telemetry: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2015-08-16 21:34:38 +00:00
|
|
|
// Create the agent
|
|
|
|
if err := c.setupAgent(config, logOutput); err != nil {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
defer c.agent.Shutdown()
|
|
|
|
|
2015-09-14 22:33:08 +00:00
|
|
|
// Check and shut down the SCADA listeners at the end
|
|
|
|
defer func() {
|
|
|
|
if c.httpServer != nil {
|
|
|
|
c.httpServer.Shutdown()
|
|
|
|
}
|
|
|
|
if c.scadaHttp != nil {
|
|
|
|
c.scadaHttp.Shutdown()
|
|
|
|
}
|
|
|
|
if c.scadaProvider != nil {
|
|
|
|
c.scadaProvider.Shutdown()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2015-12-02 19:55:29 +00:00
|
|
|
// Join startup nodes if specified
|
|
|
|
if err := c.startupJoin(config); err != nil {
|
|
|
|
c.Ui.Error(err.Error())
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2015-08-16 21:34:38 +00:00
|
|
|
// Compile agent information for output later
|
|
|
|
info := make(map[string]string)
|
|
|
|
info["client"] = strconv.FormatBool(config.Client.Enabled)
|
|
|
|
info["log level"] = config.LogLevel
|
|
|
|
info["server"] = strconv.FormatBool(config.Server.Enabled)
|
2015-09-21 20:53:49 +00:00
|
|
|
info["region"] = fmt.Sprintf("%s (DC: %s)", config.Region, config.Datacenter)
|
|
|
|
if config.Atlas != nil && config.Atlas.Infrastructure != "" {
|
|
|
|
info["atlas"] = fmt.Sprintf("(Infrastructure: '%s' Join: %v)",
|
|
|
|
config.Atlas.Infrastructure, config.Atlas.Join)
|
|
|
|
} else {
|
|
|
|
info["atlas"] = "<disabled>"
|
|
|
|
}
|
2015-08-16 21:34:38 +00:00
|
|
|
|
|
|
|
// Sort the keys for output
|
|
|
|
infoKeys := make([]string, 0, len(info))
|
|
|
|
for key := range info {
|
|
|
|
infoKeys = append(infoKeys, key)
|
|
|
|
}
|
|
|
|
sort.Strings(infoKeys)
|
|
|
|
|
|
|
|
// Agent configuration output
|
|
|
|
padding := 18
|
|
|
|
c.Ui.Output("Nomad agent configuration:\n")
|
|
|
|
for _, k := range infoKeys {
|
|
|
|
c.Ui.Info(fmt.Sprintf(
|
|
|
|
"%s%s: %s",
|
|
|
|
strings.Repeat(" ", padding-len(k)),
|
|
|
|
strings.Title(k),
|
|
|
|
info[k]))
|
|
|
|
}
|
|
|
|
c.Ui.Output("")
|
|
|
|
|
|
|
|
// Output the header that the server has started
|
|
|
|
c.Ui.Output("Nomad agent started! Log data will stream in below:\n")
|
2015-08-16 20:54:49 +00:00
|
|
|
|
|
|
|
// Enable log streaming
|
|
|
|
logGate.Flush()
|
|
|
|
|
2015-12-02 19:55:29 +00:00
|
|
|
// Start retry join process
|
2015-12-09 15:57:54 +00:00
|
|
|
c.retryJoinErrCh = make(chan struct{})
|
|
|
|
go c.retryJoin(config)
|
2015-12-02 19:55:29 +00:00
|
|
|
|
2015-08-16 20:54:49 +00:00
|
|
|
// Wait for exit
|
|
|
|
return c.handleSignals(config)
|
|
|
|
}
|
|
|
|
|
|
|
|
// handleSignals blocks until we get an exit-causing signal
|
|
|
|
func (c *Command) handleSignals(config *Config) int {
|
|
|
|
signalCh := make(chan os.Signal, 4)
|
2016-10-10 22:12:56 +00:00
|
|
|
signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGPIPE)
|
2015-08-16 20:54:49 +00:00
|
|
|
|
|
|
|
// Wait for a signal
|
|
|
|
WAIT:
|
|
|
|
var sig os.Signal
|
|
|
|
select {
|
|
|
|
case s := <-signalCh:
|
|
|
|
sig = s
|
|
|
|
case <-c.ShutdownCh:
|
|
|
|
sig = os.Interrupt
|
2015-12-09 15:57:54 +00:00
|
|
|
case <-c.retryJoinErrCh:
|
2015-12-02 19:55:29 +00:00
|
|
|
return 1
|
2015-08-16 20:54:49 +00:00
|
|
|
}
|
|
|
|
c.Ui.Output(fmt.Sprintf("Caught signal: %v", sig))
|
|
|
|
|
2016-10-10 22:12:56 +00:00
|
|
|
// Skip any SIGPIPE signal (See issue #1798)
|
|
|
|
if sig == syscall.SIGPIPE {
|
|
|
|
goto WAIT
|
|
|
|
}
|
|
|
|
|
2015-08-16 20:54:49 +00:00
|
|
|
// Check if this is a SIGHUP
|
|
|
|
if sig == syscall.SIGHUP {
|
|
|
|
if conf := c.handleReload(config); conf != nil {
|
2016-08-11 13:54:33 +00:00
|
|
|
*config = *conf
|
2015-08-16 20:54:49 +00:00
|
|
|
}
|
|
|
|
goto WAIT
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we should do a graceful leave
|
|
|
|
graceful := false
|
2015-09-21 20:54:01 +00:00
|
|
|
if sig == os.Interrupt && config.LeaveOnInt {
|
2015-08-16 20:54:49 +00:00
|
|
|
graceful = true
|
|
|
|
} else if sig == syscall.SIGTERM && config.LeaveOnTerm {
|
|
|
|
graceful = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bail fast if not doing a graceful leave
|
|
|
|
if !graceful {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt a graceful leave
|
|
|
|
gracefulCh := make(chan struct{})
|
|
|
|
c.Ui.Output("Gracefully shutting down agent...")
|
|
|
|
go func() {
|
|
|
|
if err := c.agent.Leave(); err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error: %s", err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
close(gracefulCh)
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Wait for leave or another signal
|
|
|
|
select {
|
|
|
|
case <-signalCh:
|
|
|
|
return 1
|
|
|
|
case <-time.After(gracefulTimeout):
|
|
|
|
return 1
|
|
|
|
case <-gracefulCh:
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// handleReload is invoked when we should reload our configs, e.g. SIGHUP
|
|
|
|
func (c *Command) handleReload(config *Config) *Config {
|
|
|
|
c.Ui.Output("Reloading configuration...")
|
|
|
|
newConf := c.readConfig()
|
|
|
|
if newConf == nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Failed to reload configs"))
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change the log level
|
|
|
|
minLevel := logutils.LogLevel(strings.ToUpper(newConf.LogLevel))
|
|
|
|
if ValidateLevelFilter(minLevel, c.logFilter) {
|
|
|
|
c.logFilter.SetMinLevel(minLevel)
|
|
|
|
} else {
|
|
|
|
c.Ui.Error(fmt.Sprintf(
|
|
|
|
"Invalid log level: %s. Valid log levels are: %v",
|
|
|
|
minLevel, c.logFilter.Levels))
|
|
|
|
|
|
|
|
// Keep the current log level
|
|
|
|
newConf.LogLevel = config.LogLevel
|
|
|
|
}
|
|
|
|
return newConf
|
2015-08-16 01:34:47 +00:00
|
|
|
}
|
|
|
|
|
2016-09-11 07:46:05 +00:00
|
|
|
// setupTelemetry is used ot setup the telemetry sub-systems
|
|
|
|
func (c *Command) setupTelemetry(config *Config) error {
|
2015-08-16 01:54:41 +00:00
|
|
|
/* Setup telemetry
|
|
|
|
Aggregate on 10 second intervals for 1 minute. Expose the
|
|
|
|
metrics over stderr when there is a SIGUSR1 received.
|
|
|
|
*/
|
|
|
|
inm := metrics.NewInmemSink(10*time.Second, time.Minute)
|
|
|
|
metrics.DefaultInmemSignal(inm)
|
|
|
|
|
|
|
|
var telConfig *Telemetry
|
|
|
|
if config.Telemetry == nil {
|
|
|
|
telConfig = &Telemetry{}
|
|
|
|
} else {
|
|
|
|
telConfig = config.Telemetry
|
|
|
|
}
|
|
|
|
|
2015-08-16 20:54:49 +00:00
|
|
|
metricsConf := metrics.DefaultConfig("nomad")
|
2015-08-16 01:54:41 +00:00
|
|
|
metricsConf.EnableHostname = !telConfig.DisableHostname
|
|
|
|
|
|
|
|
// Configure the statsite sink
|
|
|
|
var fanout metrics.FanoutSink
|
|
|
|
if telConfig.StatsiteAddr != "" {
|
|
|
|
sink, err := metrics.NewStatsiteSink(telConfig.StatsiteAddr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fanout = append(fanout, sink)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configure the statsd sink
|
|
|
|
if telConfig.StatsdAddr != "" {
|
|
|
|
sink, err := metrics.NewStatsdSink(telConfig.StatsdAddr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fanout = append(fanout, sink)
|
|
|
|
}
|
|
|
|
|
2016-10-15 08:49:33 +00:00
|
|
|
// Configure the datadog sink
|
|
|
|
if telConfig.DataDogAddr != "" {
|
|
|
|
sink, err := datadog.NewDogStatsdSink(telConfig.DataDogAddr, config.NodeName)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fanout = append(fanout, sink)
|
|
|
|
}
|
|
|
|
|
2016-07-22 16:33:10 +00:00
|
|
|
// Configure the Circonus sink
|
|
|
|
if telConfig.CirconusAPIToken != "" || telConfig.CirconusCheckSubmissionURL != "" {
|
|
|
|
cfg := &circonus.Config{}
|
|
|
|
cfg.Interval = telConfig.CirconusSubmissionInterval
|
|
|
|
cfg.CheckManager.API.TokenKey = telConfig.CirconusAPIToken
|
|
|
|
cfg.CheckManager.API.TokenApp = telConfig.CirconusAPIApp
|
|
|
|
cfg.CheckManager.API.URL = telConfig.CirconusAPIURL
|
|
|
|
cfg.CheckManager.Check.SubmissionURL = telConfig.CirconusCheckSubmissionURL
|
|
|
|
cfg.CheckManager.Check.ID = telConfig.CirconusCheckID
|
|
|
|
cfg.CheckManager.Check.ForceMetricActivation = telConfig.CirconusCheckForceMetricActivation
|
|
|
|
cfg.CheckManager.Check.InstanceID = telConfig.CirconusCheckInstanceID
|
|
|
|
cfg.CheckManager.Check.SearchTag = telConfig.CirconusCheckSearchTag
|
|
|
|
cfg.CheckManager.Broker.ID = telConfig.CirconusBrokerID
|
|
|
|
cfg.CheckManager.Broker.SelectTag = telConfig.CirconusBrokerSelectTag
|
|
|
|
|
|
|
|
if cfg.CheckManager.API.TokenApp == "" {
|
|
|
|
cfg.CheckManager.API.TokenApp = "nomad"
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.CheckManager.Check.InstanceID == "" {
|
|
|
|
if config.NodeName != "" && config.Datacenter != "" {
|
|
|
|
cfg.CheckManager.Check.InstanceID = fmt.Sprintf("%s:%s", config.NodeName, config.Datacenter)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.CheckManager.Check.SearchTag == "" {
|
|
|
|
cfg.CheckManager.Check.SearchTag = "service:nomad"
|
|
|
|
}
|
|
|
|
|
|
|
|
sink, err := circonus.NewCirconusSink(cfg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
sink.Start()
|
|
|
|
fanout = append(fanout, sink)
|
|
|
|
}
|
|
|
|
|
2015-08-16 01:54:41 +00:00
|
|
|
// Initialize the global sink
|
|
|
|
if len(fanout) > 0 {
|
|
|
|
fanout = append(fanout, inm)
|
|
|
|
metrics.NewGlobal(metricsConf, fanout)
|
|
|
|
} else {
|
|
|
|
metricsConf.EnableHostname = false
|
|
|
|
metrics.NewGlobal(metricsConf, inm)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-09-14 22:33:08 +00:00
|
|
|
// setupSCADA is used to start a new SCADA provider and listener,
|
|
|
|
// replacing any existing listeners.
|
|
|
|
func (c *Command) setupSCADA(config *Config) error {
|
|
|
|
// Shut down existing SCADA listeners
|
|
|
|
if c.scadaProvider != nil {
|
|
|
|
c.scadaProvider.Shutdown()
|
|
|
|
}
|
|
|
|
if c.scadaHttp != nil {
|
|
|
|
c.scadaHttp.Shutdown()
|
|
|
|
}
|
|
|
|
|
|
|
|
// No-op if we don't have an infrastructure
|
|
|
|
if config.Atlas == nil || config.Atlas.Infrastructure == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the new provider and listener
|
|
|
|
c.Ui.Output("Connecting to Atlas: " + config.Atlas.Infrastructure)
|
2016-06-01 20:34:59 +00:00
|
|
|
|
|
|
|
scadaConfig := &scada.Config{
|
|
|
|
Service: "nomad",
|
|
|
|
Version: fmt.Sprintf("%s%s", config.Version, config.VersionPrerelease),
|
|
|
|
ResourceType: "nomad-cluster",
|
|
|
|
Meta: map[string]string{
|
|
|
|
"auto-join": strconv.FormatBool(config.Atlas.Join),
|
|
|
|
"region": config.Region,
|
|
|
|
"datacenter": config.Datacenter,
|
|
|
|
"client": strconv.FormatBool(config.Client != nil && config.Client.Enabled),
|
|
|
|
"server": strconv.FormatBool(config.Server != nil && config.Server.Enabled),
|
|
|
|
},
|
|
|
|
Atlas: scada.AtlasConfig{
|
|
|
|
Endpoint: config.Atlas.Endpoint,
|
|
|
|
Infrastructure: config.Atlas.Infrastructure,
|
|
|
|
Token: config.Atlas.Token,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
provider, list, err := scada.NewHTTPProvider(scadaConfig, c.logOutput)
|
2015-09-14 22:33:08 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
c.scadaProvider = provider
|
|
|
|
c.scadaHttp = newScadaHttp(c.agent, list)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-12-02 19:55:29 +00:00
|
|
|
func (c *Command) startupJoin(config *Config) error {
|
|
|
|
if len(config.Server.StartJoin) == 0 || !config.Server.Enabled {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Ui.Output("Joining cluster...")
|
|
|
|
n, err := c.agent.server.Join(config.Server.StartJoin)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
c.Ui.Info(fmt.Sprintf("Join completed. Synced with %d initial agents", n))
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// retryJoin is used to handle retrying a join until it succeeds or all retries
|
|
|
|
// are exhausted.
|
2015-12-09 15:57:54 +00:00
|
|
|
func (c *Command) retryJoin(config *Config) {
|
2015-12-02 19:55:29 +00:00
|
|
|
if len(config.Server.RetryJoin) == 0 || !config.Server.Enabled {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
logger := c.agent.logger
|
|
|
|
logger.Printf("[INFO] agent: Joining cluster...")
|
|
|
|
|
|
|
|
attempt := 0
|
|
|
|
for {
|
|
|
|
n, err := c.agent.server.Join(config.Server.RetryJoin)
|
|
|
|
if err == nil {
|
|
|
|
logger.Printf("[INFO] agent: Join completed. Synced with %d initial agents", n)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
attempt++
|
|
|
|
if config.Server.RetryMaxAttempts > 0 && attempt > config.Server.RetryMaxAttempts {
|
2016-02-24 23:57:58 +00:00
|
|
|
logger.Printf("[ERR] agent: max join retry exhausted, exiting")
|
2015-12-09 15:57:54 +00:00
|
|
|
close(c.retryJoinErrCh)
|
2015-12-02 19:55:29 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.Printf("[WARN] agent: Join failed: %v, retrying in %v", err,
|
|
|
|
config.Server.RetryInterval)
|
|
|
|
time.Sleep(config.Server.retryInterval)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-16 01:34:47 +00:00
|
|
|
func (c *Command) Synopsis() string {
|
|
|
|
return "Runs a Nomad agent"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Command) Help() string {
|
|
|
|
helpText := `
|
|
|
|
Usage: nomad agent [options]
|
|
|
|
|
|
|
|
Starts the Nomad agent and runs until an interrupt is received.
|
|
|
|
The agent may be a client and/or server.
|
|
|
|
|
2015-09-21 21:02:36 +00:00
|
|
|
The Nomad agent's configuration primarily comes from the config
|
|
|
|
files used, but a subset of the options may also be passed directly
|
|
|
|
as CLI arguments, listed below.
|
|
|
|
|
2015-09-22 04:37:55 +00:00
|
|
|
General Options (clients and servers):
|
2015-08-16 01:34:47 +00:00
|
|
|
|
2015-09-22 04:37:55 +00:00
|
|
|
-bind=<addr>
|
|
|
|
The address the agent will bind to for all of its various network
|
|
|
|
services. The individual services that run bind to individual
|
|
|
|
ports on this address. Defaults to the loopback 127.0.0.1.
|
2015-09-22 03:38:43 +00:00
|
|
|
|
2015-09-21 21:02:36 +00:00
|
|
|
-config=<path>
|
|
|
|
The path to either a single config file or a directory of config
|
|
|
|
files to use for configuring the Nomad agent. This option may be
|
|
|
|
specified multiple times. If multiple config files are used, the
|
|
|
|
values from each will be merged together. During merging, values
|
|
|
|
from files found later in the list are merged over values from
|
|
|
|
previously parsed files.
|
|
|
|
|
2015-09-22 03:38:43 +00:00
|
|
|
-data-dir=<path>
|
|
|
|
The data directory used to store state and other persistent data.
|
|
|
|
On client machines this is used to house allocation data such as
|
|
|
|
downloaded artifacts used by drivers. On server nodes, the data
|
|
|
|
dir is also used to store the replicated log.
|
2015-09-21 21:02:36 +00:00
|
|
|
|
2015-09-22 08:59:17 +00:00
|
|
|
-dc=<datacenter>
|
2015-09-22 04:37:55 +00:00
|
|
|
The name of the datacenter this Nomad agent is a member of. By
|
|
|
|
default this is set to "dc1".
|
|
|
|
|
|
|
|
-log-level=<level>
|
|
|
|
Specify the verbosity level of Nomad's logs. Valid values include
|
|
|
|
DEBUG, INFO, and WARN, in decreasing order of verbosity. The
|
|
|
|
default is INFO.
|
|
|
|
|
|
|
|
-node=<name>
|
|
|
|
The name of the local agent. This name is used to identify the node
|
|
|
|
in the cluster. The name must be unique per region. The default is
|
|
|
|
the current hostname of the machine.
|
|
|
|
|
|
|
|
-region=<region>
|
|
|
|
Name of the region the Nomad agent will be a member of. By default
|
|
|
|
this value is set to "global".
|
|
|
|
|
2015-09-21 21:02:36 +00:00
|
|
|
-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.
|
2015-09-22 03:38:43 +00:00
|
|
|
|
2015-09-22 19:40:21 +00:00
|
|
|
Server Options:
|
|
|
|
|
2015-09-22 03:38:43 +00:00
|
|
|
-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.
|
2015-09-22 04:37:55 +00:00
|
|
|
|
2015-09-22 19:40:21 +00:00
|
|
|
-bootstrap-expect=<num>
|
|
|
|
Configures the expected number of servers nodes to wait for before
|
|
|
|
bootstrapping the cluster. Once <num> servers have joined eachother,
|
|
|
|
Nomad initiates the bootstrap process.
|
|
|
|
|
2016-10-17 17:48:04 +00:00
|
|
|
-encrypt=<key>
|
|
|
|
Provides the gossip encryption key
|
|
|
|
|
2015-12-02 19:55:29 +00:00
|
|
|
-join=<address>
|
|
|
|
Address of an agent to join at start time. Can be specified
|
|
|
|
multiple times.
|
|
|
|
|
|
|
|
-retry-join=<address>
|
|
|
|
Address of an agent to join at start time with retries enabled.
|
|
|
|
Can be specified multiple times.
|
|
|
|
|
|
|
|
-retry-max=<num>
|
|
|
|
Maximum number of join attempts. Defaults to 0, which will retry
|
|
|
|
indefinitely.
|
|
|
|
|
|
|
|
-retry-interval=<dur>
|
|
|
|
Time to wait between join attempts.
|
|
|
|
|
|
|
|
-rejoin
|
|
|
|
Ignore a previous leave and attempts to rejoin the cluster.
|
|
|
|
|
2015-09-22 19:40:21 +00:00
|
|
|
Client Options:
|
|
|
|
|
|
|
|
-client
|
2015-10-01 23:46:42 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
-state-dir
|
|
|
|
The directory used to store state and other persistent data. If not
|
|
|
|
specified a subdirectory under the "-data-dir" will be used.
|
|
|
|
|
|
|
|
-alloc-dir
|
|
|
|
The directory used to store allocation data such as downloaded artificats as
|
|
|
|
well as data produced by tasks. If not specified, a subdirectory under the
|
|
|
|
"-data-dir" will be used.
|
|
|
|
|
|
|
|
-servers
|
|
|
|
A list of known server addresses to connect to given as "host:port" and
|
|
|
|
delimited by commas.
|
|
|
|
|
|
|
|
-node-class
|
|
|
|
Mark this node as a member of a node-class. This can be used to label
|
2016-03-15 18:28:31 +00:00
|
|
|
similar node types.
|
2015-10-01 23:46:42 +00:00
|
|
|
|
|
|
|
-meta
|
|
|
|
User specified metadata to associated with the node. Each instance of -meta
|
|
|
|
parses a single KEY=VALUE pair. Repeat the meta flag for each key/value pair
|
|
|
|
to be added.
|
2015-09-22 19:40:21 +00:00
|
|
|
|
2015-10-03 00:32:11 +00:00
|
|
|
-network-interface
|
|
|
|
Forces the network fingerprinter to use the specified network interface.
|
|
|
|
|
|
|
|
-network-speed
|
|
|
|
The default speed for network interfaces in MBits if the link speed can not
|
|
|
|
be determined dynamically.
|
|
|
|
|
2016-09-01 22:41:07 +00:00
|
|
|
Vault Options:
|
|
|
|
|
|
|
|
-vault-enabled
|
|
|
|
Whether to enable or disable Vault integration.
|
|
|
|
|
|
|
|
-vault-address=<addr>
|
|
|
|
The address to communicate with Vault. This should be provided with the http://
|
|
|
|
or https:// prefix.
|
|
|
|
|
|
|
|
-vault-token=<token>
|
|
|
|
The Vault token used to derive tokens from Vault on behalf of clients.
|
|
|
|
This only needs to be set on Servers.
|
|
|
|
|
|
|
|
-vault-allow-unauthenticated
|
|
|
|
Whether to allow jobs to be sumbitted that request Vault Tokens but do not
|
|
|
|
authentication. The flag only applies to Servers.
|
|
|
|
|
2015-09-22 04:37:55 +00:00
|
|
|
Atlas Options:
|
|
|
|
|
|
|
|
-atlas=<infrastructure>
|
|
|
|
The Atlas infrastructure name to configure. This enables the SCADA
|
|
|
|
client and attempts to connect Nomad to the HashiCorp Atlas service
|
|
|
|
using the provided infrastructure name and token.
|
|
|
|
|
|
|
|
-atlas-token=<token>
|
|
|
|
The Atlas token to use when connecting to the HashiCorp Atlas
|
|
|
|
service. This must be provided to successfully connect your Nomad
|
|
|
|
agent to Atlas.
|
|
|
|
|
|
|
|
-atlas-join
|
|
|
|
Enable the Atlas join feature. This mode allows agents to discover
|
|
|
|
eachother automatically using the SCADA integration features.
|
2015-08-16 01:34:47 +00:00
|
|
|
`
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|