Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the auto-register flag #1174

Merged
merged 2 commits into from
May 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -788,6 +788,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