Auto-register the consul service

This commit is contained in:
Armon Dadgar 2014-01-09 17:57:13 -08:00
parent 0f0f29eb31
commit 8c6f03ad07
2 changed files with 15 additions and 1 deletions

View File

@ -253,7 +253,11 @@ func TestCatalogListServices(t *testing.T) {
t.Fatalf("err: %v", err)
}
if len(out) != 1 {
if len(out) != 2 {
t.Fatalf("bad: %v", out)
}
// Consul service should auto-register
if len(out["consul"]) != 1 {
t.Fatalf("bad: %v", out)
}
if len(out["db"]) != 1 {

View File

@ -132,11 +132,21 @@ func (s *Server) handleAliveMember(member serf.Member) error {
}
s.logger.Printf("[INFO] consul: member '%s' joined, marking health alive", member.Name)
// Register consul service if a server
var service *structs.NodeService
if valid, _, port := isConsulServer(member); valid {
service = &structs.NodeService{
Service: "consul",
Port: port,
}
}
// Register with the catalog
req := structs.RegisterRequest{
Datacenter: s.config.Datacenter,
Node: member.Name,
Address: member.Addr.String(),
Service: service,
Check: &structs.HealthCheck{
Node: member.Name,
CheckID: serfCheckID,