github.com/akerouanton/docker@v1.11.0-rc3/container/monitor.go (about) 1 package container 2 3 import ( 4 "time" 5 6 "github.com/Sirupsen/logrus" 7 ) 8 9 const ( 10 loggerCloseTimeout = 10 * time.Second 11 ) 12 13 // supervisor defines the interface that a supervisor must implement 14 type supervisor interface { 15 // LogContainerEvent generates events related to a given container 16 LogContainerEvent(*Container, string) 17 // Cleanup ensures that the container is properly unmounted 18 Cleanup(*Container) 19 // StartLogging starts the logging driver for the container 20 StartLogging(*Container) error 21 // Run starts a container 22 Run(c *Container) error 23 // IsShuttingDown tells whether the supervisor is shutting down or not 24 IsShuttingDown() bool 25 } 26 27 // Reset puts a container into a state where it can be restarted again. 28 func (container *Container) Reset(lock bool) { 29 if lock { 30 container.Lock() 31 defer container.Unlock() 32 } 33 34 if err := container.CloseStreams(); err != nil { 35 logrus.Errorf("%s: %s", container.ID, err) 36 } 37 38 // Re-create a brand new stdin pipe once the container exited 39 if container.Config.OpenStdin { 40 container.NewInputPipes() 41 } 42 43 if container.LogDriver != nil { 44 if container.LogCopier != nil { 45 exit := make(chan struct{}) 46 go func() { 47 container.LogCopier.Wait() 48 close(exit) 49 }() 50 select { 51 case <-time.After(loggerCloseTimeout): 52 logrus.Warnf("Logger didn't exit in time: logs may be truncated") 53 case <-exit: 54 } 55 } 56 container.LogDriver.Close() 57 container.LogCopier = nil 58 container.LogDriver = nil 59 } 60 }