Skip to content

Commit

Permalink
Merge pull request #1174 from hashicorp/f-config-consul-block
Browse files Browse the repository at this point in the history
Using the auto-register flag
  • Loading branch information
diptanu committed May 18, 2016
2 parents 320a5cb + e0cddec commit 6b0757c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
18 changes: 13 additions & 5 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -426,7 +427,6 @@ func DefaultConfig() *Config {
ConsulConfig: &ConsulConfig{
ServerServiceName: "nomad-server",
ClientServiceName: "nomad-client",
AutoRegister: true,
},
Client: &ClientConfig{
Enabled: false,
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions command/agent/config_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 6b0757c

Please sign in to comment.