diff --git a/command/agent/agent.go b/command/agent/agent.go index 78c4639130f..6f12d3896e2 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -69,11 +69,13 @@ func NewAgent(config *Config, logOutput io.Writer) (*Agent, error) { if a.client == nil && a.server == nil { return nil, fmt.Errorf("must have at least client or server mode enabled") } - if err := a.syncAgentServicesWithConsul(a.serverHTTPAddr, a.clientHTTPAddr); err != nil { - a.logger.Printf("[ERR] agent: unable to sync agent services with consul: %v", err) - } - if a.consulService != nil { - go a.consulService.PeriodicSync() + if a.config.ConsulConfig.AutoRegister { + if err := a.syncAgentServicesWithConsul(a.serverHTTPAddr, a.clientHTTPAddr); err != nil { + a.logger.Printf("[ERR] agent: unable to sync agent services with consul: %v", err) + } + if a.consulService != nil { + go a.consulService.PeriodicSync() + } } return a, nil } @@ -523,6 +525,12 @@ func (a *Agent) syncAgentServicesWithConsul(clientHttpAddr string, serverHttpAdd if err != nil { return "", 0 } + + // if the addr for the service is ":port", then we default to + // registering the service with ip as the loopback addr + if host == "" { + host = "127.0.0.1" + } p, err := strconv.Atoi(port) if err != nil { return "", 0 diff --git a/command/agent/config.go b/command/agent/config.go index 967171efaf0..ee99d32e660 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -396,6 +396,7 @@ func DevConfig() *Config { conf.DevMode = true conf.EnableDebug = true conf.DisableAnonymousSignature = true + conf.ConsulConfig.AutoRegister = true if runtime.GOOS == "darwin" { conf.Client.NetworkInterface = "lo0" } else if runtime.GOOS == "linux" { @@ -426,7 +427,6 @@ func DefaultConfig() *Config { ConsulConfig: &ConsulConfig{ ServerServiceName: "nomad-server", ClientServiceName: "nomad-client", - AutoRegister: true, }, Client: &ClientConfig{ Enabled: false, @@ -796,6 +796,9 @@ func (a *ConsulConfig) Merge(b *ConsulConfig) *ConsulConfig { if b.ClientServiceName != "" { result.ClientServiceName = b.ClientServiceName } + if b.AutoRegister { + result.AutoRegister = true + } if b.Addr != "" { result.Addr = b.Addr } diff --git a/command/agent/config_parse.go b/command/agent/config_parse.go index 69b6a626def..089493cc383 100644 --- a/command/agent/config_parse.go +++ b/command/agent/config_parse.go @@ -552,6 +552,7 @@ func parseConsulConfig(result **ConsulConfig, list *ast.ObjectList) error { valid := []string{ "server_service_name", "client_service_name", + "auto_register", "addr", "token", "auth", diff --git a/main.go b/main.go index 073e46d52de..212c28f502a 100644 --- a/main.go +++ b/main.go @@ -35,6 +35,7 @@ func RunCustom(args []string, commands map[string]cli.CommandFactory) int { case "executor": case "syslog": case "fs ls", "fs cat", "fs stat": + case "check": default: commandsInclude = append(commandsInclude, k) }