From 8c6f03ad07bd72b23ce0c862616bb299ee9b8364 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Thu, 9 Jan 2014 17:57:13 -0800 Subject: [PATCH] Auto-register the consul service --- consul/catalog_endpoint_test.go | 6 +++++- consul/leader.go | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/consul/catalog_endpoint_test.go b/consul/catalog_endpoint_test.go index 423ed106a7..222a96684b 100644 --- a/consul/catalog_endpoint_test.go +++ b/consul/catalog_endpoint_test.go @@ -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 { diff --git a/consul/leader.go b/consul/leader.go index 10355e54a6..be7f7ac182 100644 --- a/consul/leader.go +++ b/consul/leader.go @@ -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,