2018-02-05 16:05:59 -05:00
|
|
|
package container // import "github.com/docker/docker/container"
|
2014-08-04 20:05:56 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2017-07-26 17:42:13 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2014-08-04 20:05:56 -04:00
|
|
|
)
|
|
|
|
|
2015-07-03 09:50:06 -04:00
|
|
|
const (
|
2016-03-18 14:50:19 -04:00
|
|
|
loggerCloseTimeout = 10 * time.Second
|
2015-07-03 09:50:06 -04:00
|
|
|
)
|
2014-08-04 21:20:53 -04:00
|
|
|
|
2016-03-18 14:50:19 -04:00
|
|
|
// Reset puts a container into a state where it can be restarted again.
|
|
|
|
func (container *Container) Reset(lock bool) {
|
2014-08-28 07:39:27 -04:00
|
|
|
if lock {
|
|
|
|
container.Lock()
|
|
|
|
defer container.Unlock()
|
|
|
|
}
|
2014-08-11 14:07:37 -04:00
|
|
|
|
2015-11-17 19:21:44 -05:00
|
|
|
if err := container.CloseStreams(); err != nil {
|
|
|
|
logrus.Errorf("%s: %s", container.ID, err)
|
2014-08-11 14:07:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Re-create a brand new stdin pipe once the container exited
|
|
|
|
if container.Config.OpenStdin {
|
2016-11-14 15:15:09 -05:00
|
|
|
container.StreamConfig.NewInputPipes()
|
2014-08-11 14:07:37 -04:00
|
|
|
}
|
|
|
|
|
2015-11-12 14:55:17 -05:00
|
|
|
if container.LogDriver != nil {
|
|
|
|
if container.LogCopier != nil {
|
2015-03-18 14:44:14 -04:00
|
|
|
exit := make(chan struct{})
|
|
|
|
go func() {
|
2015-11-12 14:55:17 -05:00
|
|
|
container.LogCopier.Wait()
|
2015-03-18 14:44:14 -04:00
|
|
|
close(exit)
|
|
|
|
}()
|
|
|
|
select {
|
2015-07-03 09:50:06 -04:00
|
|
|
case <-time.After(loggerCloseTimeout):
|
2016-06-11 13:42:38 -04:00
|
|
|
logrus.Warn("Logger didn't exit in time: logs may be truncated")
|
2015-03-18 14:44:14 -04:00
|
|
|
case <-exit:
|
|
|
|
}
|
|
|
|
}
|
2015-11-12 14:55:17 -05:00
|
|
|
container.LogDriver.Close()
|
|
|
|
container.LogCopier = nil
|
|
|
|
container.LogDriver = nil
|
2015-02-04 14:04:58 -05:00
|
|
|
}
|
2015-11-03 12:33:13 -05:00
|
|
|
}
|