agent: Fix issues with re-registration. Fixes #216

pull/233/head
Armon Dadgar 2014-06-17 16:48:19 -07:00
parent ca2bbb0a1b
commit 10c120bf9d
1 changed files with 4 additions and 5 deletions

View File

@ -393,7 +393,6 @@ func (a *Agent) AddService(service *structs.NodeService, chkType *CheckType) err
ServiceName: service.Service, ServiceName: service.Service,
} }
if err := a.AddCheck(check, chkType); err != nil { if err := a.AddCheck(check, chkType); err != nil {
a.state.RemoveService(service.ID)
return err return err
} }
} }
@ -429,8 +428,8 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *CheckType) error {
// Check if already registered // Check if already registered
if chkType != nil { if chkType != nil {
if chkType.IsTTL() { if chkType.IsTTL() {
if _, ok := a.checkTTLs[check.CheckID]; ok { if existing, ok := a.checkTTLs[check.CheckID]; ok {
return fmt.Errorf("CheckID is already registered") existing.Stop()
} }
ttl := &CheckTTL{ ttl := &CheckTTL{
@ -443,8 +442,8 @@ func (a *Agent) AddCheck(check *structs.HealthCheck, chkType *CheckType) error {
a.checkTTLs[check.CheckID] = ttl a.checkTTLs[check.CheckID] = ttl
} else { } else {
if _, ok := a.checkMonitors[check.CheckID]; ok { if existing, ok := a.checkMonitors[check.CheckID]; ok {
return fmt.Errorf("CheckID is already registered") existing.Stop()
} }
if chkType.Interval < MinInterval { if chkType.Interval < MinInterval {
a.logger.Println(fmt.Sprintf("[WARN] agent: check '%s' has interval below minimum of %v", a.logger.Println(fmt.Sprintf("[WARN] agent: check '%s' has interval below minimum of %v",