Skip to content

Commit

Permalink
Merge pull request #1645 from capone212/failing_cehcks_fix
Browse files Browse the repository at this point in the history
issue #1636:  start CheckRunner if check exists in consul already
  • Loading branch information
diptanu authored Aug 24, 2016
2 parents a417004 + 7f53d02 commit 4a3eee9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions command/agent/consul/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ func (r *CheckRunner) Start() {
r.started = true
}

// Started returns if the check runner has started running
func (r *CheckRunner) Started() bool {
r.startedLock.Lock()
defer r.startedLock.Unlock()
return r.started
}

// Stop is used to stop the check.
func (r *CheckRunner) Stop() {
r.stopLock.Lock()
Expand Down
15 changes: 14 additions & 1 deletion command/agent/consul/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func (c *Syncer) syncChecks() error {
}

// Synchronize checks with Consul
missingChecks, _, changedChecks, staleChecks := c.calcChecksDiff(consulChecks)
missingChecks, existingChecks, changedChecks, staleChecks := c.calcChecksDiff(consulChecks)
for _, check := range missingChecks {
if err := c.registerCheck(check); err != nil {
mErr.Errors = append(mErr.Errors, err)
Expand All @@ -403,6 +403,9 @@ func (c *Syncer) syncChecks() error {
c.trackedChecks[consulCheckID(check.ID)] = check
c.registryLock.Unlock()
}
for _, check := range existingChecks {
c.ensureCheckRunning(check)
}
for _, check := range changedChecks {
// NOTE(sean@): Do we need to deregister the check before
// re-registering it? Not deregistering to avoid missing the
Expand Down Expand Up @@ -684,6 +687,16 @@ func (c *Syncer) registerCheck(chkReg *consul.AgentCheckRegistration) error {
return c.client.Agent().CheckRegister(chkReg)
}

// ensureCheckRunning starts the check runner for a check if it's not already running
func (c *Syncer) ensureCheckRunning(chk *consul.AgentCheckRegistration) {
c.registryLock.RLock()
defer c.registryLock.RUnlock()
if cr, ok := c.checkRunners[consulCheckID(chk.ID)]; ok && !cr.Started() {
c.logger.Printf("[DEBUG] consul.syncer: starting runner for existing check. %v", chk.ID)
cr.Start()
}
}

// createCheckReg creates a Check that can be registered with Nomad. It also
// creates a Nomad check for the check types that it can handle.
func (c *Syncer) createCheckReg(check *structs.ServiceCheck, serviceReg *consul.AgentServiceRegistration) (*consul.AgentCheckRegistration, error) {
Expand Down

0 comments on commit 4a3eee9

Please sign in to comment.