blob: 7a459d818269d1a113a248626320bd09b295d0b5 [file] [log] [blame]
package container
import (
// Health holds the current container health-check state
type Health struct {
stop chan struct{} // Write struct{} to stop the monitor
// String returns a human-readable description of the health-check state
func (s *Health) String() string {
// This happens when the container is being shutdown and the monitor has stopped
// or the monitor has yet to be setup.
if s.stop == nil {
return types.Unhealthy
switch s.Status {
case types.Starting:
return "health: starting"
default: // Healthy and Unhealthy are clear on their own
return s.Status
// OpenMonitorChannel creates and returns a new monitor channel. If there already is one,
// it returns nil.
func (s *Health) OpenMonitorChannel() chan struct{} {
if s.stop == nil {
s.stop = make(chan struct{})
return s.stop
return nil
// CloseMonitorChannel closes any existing monitor channel.
func (s *Health) CloseMonitorChannel() {
if s.stop != nil {
logrus.Debug("CloseMonitorChannel: waiting for probe to stop")
// This channel does not buffer. Once the write succeeds, the monitor
// has read the stop request and will not make any further updates
// to c.State.Health.
s.stop <- struct{}{}
s.stop = nil
logrus.Debug("CloseMonitorChannel done")