github.com/jingleWang/moby@v1.13.1/container/health.go (about) 1 package container 2 3 import ( 4 "github.com/Sirupsen/logrus" 5 "github.com/docker/docker/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 // This happens when the container is being shutdown and the monitor has stopped 17 // or the monitor has yet to be setup. 18 if s.stop == nil { 19 return types.Unhealthy 20 } 21 22 switch s.Status { 23 case types.Starting: 24 return "health: starting" 25 default: // Healthy and Unhealthy are clear on their own 26 return s.Status 27 } 28 } 29 30 // OpenMonitorChannel creates and returns a new monitor channel. If there already is one, 31 // it returns nil. 32 func (s *Health) OpenMonitorChannel() chan struct{} { 33 if s.stop == nil { 34 logrus.Debug("OpenMonitorChannel") 35 s.stop = make(chan struct{}) 36 return s.stop 37 } 38 return nil 39 } 40 41 // CloseMonitorChannel closes any existing monitor channel. 42 func (s *Health) CloseMonitorChannel() { 43 if s.stop != nil { 44 logrus.Debug("CloseMonitorChannel: waiting for probe to stop") 45 close(s.stop) 46 s.stop = nil 47 logrus.Debug("CloseMonitorChannel done") 48 } 49 }