github.com/noxiouz/docker@v0.7.3-0.20160629055221-3d231c78e8c5/container/health.go (about) 1 package container 2 3 import ( 4 "github.com/Sirupsen/logrus" 5 "github.com/docker/engine-api/types" 6 ) 7 8 // Health holds the current container health-check state 9 type Health struct { 10 types.Health 11 stop chan struct{} // Write struct{} to stop the monitor 12 } 13 14 // String returns a human-readable description of the health-check state 15 func (s *Health) String() string { 16 if s.stop == nil { 17 return "no healthcheck" 18 } 19 switch s.Status { 20 case types.Starting: 21 return "health: starting" 22 default: // Healthy and Unhealthy are clear on their own 23 return s.Status 24 } 25 } 26 27 // OpenMonitorChannel creates and returns a new monitor channel. If there already is one, 28 // it returns nil. 29 func (s *Health) OpenMonitorChannel() chan struct{} { 30 if s.stop == nil { 31 logrus.Debug("OpenMonitorChannel") 32 s.stop = make(chan struct{}) 33 return s.stop 34 } 35 return nil 36 } 37 38 // CloseMonitorChannel closes any existing monitor channel. 39 func (s *Health) CloseMonitorChannel() { 40 if s.stop != nil { 41 logrus.Debug("CloseMonitorChannel: waiting for probe to stop") 42 // This channel does not buffer. Once the write succeeds, the monitor 43 // has read the stop request and will not make any further updates 44 // to c.State.Health. 45 s.stop <- struct{}{} 46 s.stop = nil 47 logrus.Debug("CloseMonitorChannel done") 48 } 49 }