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