2015-11-12 14:55:17 -05:00
|
|
|
package container
|
2014-08-04 20:05:56 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2015-03-26 18:22:04 -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
|
|
|
|
2015-11-12 14:55:17 -05:00
|
|
|
// supervisor defines the interface that a supervisor must implement
|
|
|
|
type supervisor interface {
|
2015-11-03 12:33:13 -05:00
|
|
|
// LogContainerEvent generates events related to a given container
|
|
|
|
LogContainerEvent(*Container, string)
|
2015-11-03 12:43:36 -05:00
|
|
|
// Cleanup ensures that the container is properly unmounted
|
|
|
|
Cleanup(*Container)
|
2015-11-03 13:45:12 -05:00
|
|
|
// StartLogging starts the logging driver for the container
|
|
|
|
StartLogging(*Container) error
|
2015-11-03 14:25:22 -05:00
|
|
|
// Run starts a container
|
2016-03-18 14:50:19 -04:00
|
|
|
Run(c *Container) error
|
2015-11-03 14:25:22 -05:00
|
|
|
// IsShuttingDown tells whether the supervisor is shutting down or not
|
|
|
|
IsShuttingDown() bool
|
2015-11-03 12:33:13 -05: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 {
|
2015-11-17 19:21:44 -05:00
|
|
|
container.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):
|
2015-03-26 18:22:04 -04:00
|
|
|
logrus.Warnf("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
|
|
|
}
|