6bb0d181 |
package container |
2b0776c8 |
import (
"time"
|
1009e6a4 |
"github.com/sirupsen/logrus" |
2b0776c8 |
)
|
c0391bf5 |
const ( |
9c4570a9 |
loggerCloseTimeout = 10 * time.Second |
c0391bf5 |
) |
860c13b7 |
|
9c4570a9 |
// Reset puts a container into a state where it can be restarted again.
func (container *Container) Reset(lock bool) { |
517ba44e |
if lock {
container.Lock()
defer container.Unlock()
} |
a2afb2b1 |
|
3f5b8f71 |
if err := container.CloseStreams(); err != nil {
logrus.Errorf("%s: %s", container.ID, err) |
a2afb2b1 |
}
// Re-create a brand new stdin pipe once the container exited
if container.Config.OpenStdin { |
5ea75bb6 |
container.StreamConfig.NewInputPipes() |
a2afb2b1 |
}
|
6bb0d181 |
if container.LogDriver != nil {
if container.LogCopier != nil { |
b6a42673 |
exit := make(chan struct{})
go func() { |
6bb0d181 |
container.LogCopier.Wait() |
b6a42673 |
close(exit)
}()
select { |
c0391bf5 |
case <-time.After(loggerCloseTimeout): |
44ccbb31 |
logrus.Warn("Logger didn't exit in time: logs may be truncated") |
b6a42673 |
case <-exit:
}
} |
6bb0d181 |
container.LogDriver.Close()
container.LogCopier = nil
container.LogDriver = nil |
47a6afb9 |
} |
ca5ede2d |
} |