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) 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) t.Fatalf("bad: %v", out)
} }
if len(out["db"]) != 1 { 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) 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 // Register with the catalog
req := structs.RegisterRequest{ req := structs.RegisterRequest{
Datacenter: s.config.Datacenter, Datacenter: s.config.Datacenter,
Node: member.Name, Node: member.Name,
Address: member.Addr.String(), Address: member.Addr.String(),
Service: service,
Check: &structs.HealthCheck{ Check: &structs.HealthCheck{
Node: member.Name, Node: member.Name,
CheckID: serfCheckID, CheckID: serfCheckID,