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