Merge pull request #1645 from capone212/failing_cehcks_fix
issue #1636: start CheckRunner if check exists in consul already
This commit is contained in:
commit
b80147d183
|
@ -47,6 +47,13 @@ func (r *CheckRunner) Start() {
|
||||||
r.started = true
|
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.
|
// Stop is used to stop the check.
|
||||||
func (r *CheckRunner) Stop() {
|
func (r *CheckRunner) Stop() {
|
||||||
r.stopLock.Lock()
|
r.stopLock.Lock()
|
||||||
|
|
|
@ -394,7 +394,7 @@ func (c *Syncer) syncChecks() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synchronize checks with Consul
|
// Synchronize checks with Consul
|
||||||
missingChecks, _, changedChecks, staleChecks := c.calcChecksDiff(consulChecks)
|
missingChecks, existingChecks, changedChecks, staleChecks := c.calcChecksDiff(consulChecks)
|
||||||
for _, check := range missingChecks {
|
for _, check := range missingChecks {
|
||||||
if err := c.registerCheck(check); err != nil {
|
if err := c.registerCheck(check); err != nil {
|
||||||
mErr.Errors = append(mErr.Errors, err)
|
mErr.Errors = append(mErr.Errors, err)
|
||||||
|
@ -403,6 +403,9 @@ func (c *Syncer) syncChecks() error {
|
||||||
c.trackedChecks[consulCheckID(check.ID)] = check
|
c.trackedChecks[consulCheckID(check.ID)] = check
|
||||||
c.registryLock.Unlock()
|
c.registryLock.Unlock()
|
||||||
}
|
}
|
||||||
|
for _, check := range existingChecks {
|
||||||
|
c.ensureCheckRunning(check)
|
||||||
|
}
|
||||||
for _, check := range changedChecks {
|
for _, check := range changedChecks {
|
||||||
// NOTE(sean@): Do we need to deregister the check before
|
// NOTE(sean@): Do we need to deregister the check before
|
||||||
// re-registering it? Not deregistering to avoid missing the
|
// re-registering it? Not deregistering to avoid missing the
|
||||||
|
@ -684,6 +687,16 @@ func (c *Syncer) registerCheck(chkReg *consul.AgentCheckRegistration) error {
|
||||||
return c.client.Agent().CheckRegister(chkReg)
|
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
|
// createCheckReg creates a Check that can be registered with Nomad. It also
|
||||||
// creates a Nomad check for the check types that it can handle.
|
// 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) {
|
func (c *Syncer) createCheckReg(check *structs.ServiceCheck, serviceReg *consul.AgentServiceRegistration) (*consul.AgentCheckRegistration, error) {
|
||||||
|
|
Loading…
Reference in New Issue