github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/container/monitor.go (about) 1 package container // import "github.com/demonoid81/moby/container" 2 3 import ( 4 "time" 5 6 "github.com/sirupsen/logrus" 7 ) 8 9 const ( 10 loggerCloseTimeout = 10 * time.Second 11 ) 12 13 // Reset puts a container into a state where it can be restarted again. 14 func (container *Container) Reset(lock bool) { 15 if lock { 16 container.Lock() 17 defer container.Unlock() 18 } 19 20 if err := container.CloseStreams(); err != nil { 21 logrus.Errorf("%s: %s", container.ID, err) 22 } 23 24 // Re-create a brand new stdin pipe once the container exited 25 if container.Config.OpenStdin { 26 container.StreamConfig.NewInputPipes() 27 } 28 29 if container.LogDriver != nil { 30 if container.LogCopier != nil { 31 exit := make(chan struct{}) 32 go func() { 33 container.LogCopier.Wait() 34 close(exit) 35 }() 36 37 timer := time.NewTimer(loggerCloseTimeout) 38 defer timer.Stop() 39 select { 40 case <-timer.C: 41 logrus.Warn("Logger didn't exit in time: logs may be truncated") 42 case <-exit: 43 } 44 } 45 container.LogDriver.Close() 46 container.LogCopier = nil 47 container.LogDriver = nil 48 } 49 }