mirror of https://github.com/hashicorp/consul
Adding CheckMonitors and CheckTTLs to agent
parent
410a0de0c8
commit
c4f516d034
|
@ -33,13 +33,20 @@ type Agent struct {
|
||||||
server *consul.Server
|
server *consul.Server
|
||||||
client *consul.Client
|
client *consul.Client
|
||||||
|
|
||||||
shutdown bool
|
|
||||||
shutdownCh chan struct{}
|
|
||||||
shutdownLock sync.Mutex
|
|
||||||
|
|
||||||
// state stores a local representation of the node,
|
// state stores a local representation of the node,
|
||||||
// services and checks. Used for anti-entropy.
|
// services and checks. Used for anti-entropy.
|
||||||
state localState
|
state localState
|
||||||
|
|
||||||
|
// checkMonitors maps the check ID to an associated monitor
|
||||||
|
// checkTTLs maps the check ID to an associated check TTL
|
||||||
|
// checkLock protects updates to either
|
||||||
|
checkMonitors map[string]*CheckMonitor
|
||||||
|
checkTTLs map[string]*CheckTTL
|
||||||
|
checkLock sync.Mutex
|
||||||
|
|
||||||
|
shutdown bool
|
||||||
|
shutdownCh chan struct{}
|
||||||
|
shutdownLock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create is used to create a new Agent. Returns
|
// Create is used to create a new Agent. Returns
|
||||||
|
@ -80,6 +87,8 @@ func Create(config *Config, logOutput io.Writer) (*Agent, error) {
|
||||||
config: config,
|
config: config,
|
||||||
logger: log.New(logOutput, "", log.LstdFlags),
|
logger: log.New(logOutput, "", log.LstdFlags),
|
||||||
logOutput: logOutput,
|
logOutput: logOutput,
|
||||||
|
checkMonitors: make(map[string]*CheckMonitor),
|
||||||
|
checkTTLs: make(map[string]*CheckTTL),
|
||||||
shutdownCh: make(chan struct{}),
|
shutdownCh: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,6 +214,16 @@ func (a *Agent) Shutdown() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop all the checks
|
||||||
|
a.checkLock.Lock()
|
||||||
|
defer a.checkLock.Unlock()
|
||||||
|
for _, chk := range a.checkMonitors {
|
||||||
|
chk.Stop()
|
||||||
|
}
|
||||||
|
for _, chk := range a.checkTTLs {
|
||||||
|
chk.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
a.logger.Println("[INFO] agent: requesting shutdown")
|
a.logger.Println("[INFO] agent: requesting shutdown")
|
||||||
var err error
|
var err error
|
||||||
if a.server != nil {
|
if a.server != nil {
|
||||||
|
|
Loading…
Reference in New Issue