Skip to content

Commit

Permalink
Merge pull request #1349 from hashicorp/f-vault-service
Browse files Browse the repository at this point in the history
Vault-driven Consul service registration and TTL checks.
  • Loading branch information
sean- committed Apr 26, 2016
2 parents 9781014 + 4db1635 commit 4100a42
Show file tree
Hide file tree
Showing 14 changed files with 1,021 additions and 33 deletions.
3 changes: 2 additions & 1 deletion command/config.go
Expand Up @@ -53,9 +53,10 @@ func LoadConfig(path string) (*DefaultConfig, error) {
path = v
}

// NOTE: requires HOME env var to be set
path, err := homedir.Expand(path)
if err != nil {
return nil, fmt.Errorf("Error expanding config path: %s", err)
return nil, fmt.Errorf("Error expanding config path %s: %s", path, err)
}

contents, err := ioutil.ReadFile(path)
Expand Down
13 changes: 12 additions & 1 deletion command/server.go
Expand Up @@ -205,7 +205,7 @@ func (c *ServerCommand) Run(args []string) int {
coreConfig.AdvertiseAddr = envAA
}

// Attempt to detect the advertise address possible
// Attempt to detect the advertise address, if possible
var detect physical.AdvertiseDetect
if coreConfig.HAPhysical != nil {
detect, ok = coreConfig.HAPhysical.(physical.AdvertiseDetect)
Expand Down Expand Up @@ -286,6 +286,17 @@ func (c *ServerCommand) Run(args []string) int {
}
}

// If the backend supports service discovery, run service discovery
if coreConfig.HAPhysical != nil {
sd, ok := coreConfig.HAPhysical.(physical.ServiceDiscovery)
if ok {
if err := sd.RunServiceDiscovery(c.ShutdownCh, coreConfig.AdvertiseAddr); err != nil {
c.Ui.Error(fmt.Sprintf("Error initializing service discovery: %v", err))
return 1
}
}
}

// Initialize the listeners
lns := make([]net.Listener, 0, len(config.Listeners))
for i, lnConfig := range config.Listeners {
Expand Down
4 changes: 2 additions & 2 deletions command/server/config.go
Expand Up @@ -365,7 +365,7 @@ func parseBackends(result *Config, list *ast.ObjectList) error {
return multierror.Prefix(err, fmt.Sprintf("backend.%s:", key))
}

// Pull out the advertise address since it's commong to all backends
// Pull out the advertise address since it's common to all backends
var advertiseAddr string
if v, ok := m["advertise_addr"]; ok {
advertiseAddr = v
Expand Down Expand Up @@ -398,7 +398,7 @@ func parseHABackends(result *Config, list *ast.ObjectList) error {
return multierror.Prefix(err, fmt.Sprintf("ha_backend.%s:", key))
}

// Pull out the advertise address since it's commong to all backends
// Pull out the advertise address since it's common to all backends
var advertiseAddr string
if v, ok := m["advertise_addr"]; ok {
advertiseAddr = v
Expand Down
6 changes: 4 additions & 2 deletions command/server_test.go
Expand Up @@ -32,13 +32,15 @@ listener "tcp" {
consulhcl = `
backend "consul" {
prefix = "foo/"
advertise_addr = "http://127.0.0.1:8200"
advertise_addr = "http://127.0.0.1:8200"
disable_registration = "true"
}
`
haconsulhcl = `
ha_backend "consul" {
prefix = "bar/"
advertise_addr = "http://127.0.0.1:8200"
advertise_addr = "http://127.0.0.1:8200"
disable_registration = "true"
}
`

Expand Down

0 comments on commit 4100a42

Please sign in to comment.