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