2014-08-05 00:05:56 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"os/exec"
|
2015-07-29 12:21:16 +00:00
|
|
|
"strings"
|
2014-08-05 00:05:56 +00:00
|
|
|
"sync"
|
2015-07-29 12:21:16 +00:00
|
|
|
"syscall"
|
2014-08-05 00:05:56 +00:00
|
|
|
"time"
|
|
|
|
|
2015-03-26 22:22:04 +00:00
|
|
|
"github.com/Sirupsen/logrus"
|
2014-10-24 22:11:48 +00:00
|
|
|
"github.com/docker/docker/daemon/execdriver"
|
2015-07-29 12:21:16 +00:00
|
|
|
derr "github.com/docker/docker/errors"
|
2015-03-24 11:25:26 +00:00
|
|
|
"github.com/docker/docker/pkg/stringid"
|
2014-08-05 00:05:56 +00:00
|
|
|
"github.com/docker/docker/runconfig"
|
2015-07-29 12:21:16 +00:00
|
|
|
"github.com/docker/docker/utils"
|
2014-08-05 00:05:56 +00:00
|
|
|
)
|
|
|
|
|
2015-07-03 13:50:06 +00:00
|
|
|
const (
|
|
|
|
defaultTimeIncrement = 100
|
|
|
|
loggerCloseTimeout = 10 * time.Second
|
|
|
|
)
|
2014-08-05 01:20:53 +00:00
|
|
|
|
2015-11-03 17:33:13 +00:00
|
|
|
// containerSupervisor defines the interface that a supervisor must implement
|
|
|
|
type containerSupervisor interface {
|
|
|
|
// 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
|
|
|
|
Run(c *Container, pipes *execdriver.Pipes, startCallback execdriver.DriverCallback) (execdriver.ExitStatus, error)
|
|
|
|
// IsShuttingDown tells whether the supervisor is shutting down or not
|
|
|
|
IsShuttingDown() bool
|
2015-11-03 17:33:13 +00:00
|
|
|
}
|
|
|
|
|
2014-08-05 00:05:56 +00:00
|
|
|
// containerMonitor monitors the execution of a container's main process.
|
2015-01-06 03:33:53 +00:00
|
|
|
// If a restart policy is specified for the container the monitor will ensure that the
|
2014-08-05 00:05:56 +00:00
|
|
|
// process is restarted based on the rules of the policy. When the container is finally stopped
|
|
|
|
// the monitor will reset and cleanup any of the container resources such as networking allocations
|
|
|
|
// and the rootfs
|
|
|
|
type containerMonitor struct {
|
|
|
|
mux sync.Mutex
|
|
|
|
|
2015-11-03 17:33:13 +00:00
|
|
|
// supervisor keeps track of the container and the events it generates
|
|
|
|
supervisor containerSupervisor
|
|
|
|
|
2014-08-05 01:20:53 +00:00
|
|
|
// container is the container being monitored
|
|
|
|
container *Container
|
|
|
|
|
2014-08-13 21:56:35 +00:00
|
|
|
// restartPolicy is the current policy being applied to the container monitor
|
2014-08-05 00:05:56 +00:00
|
|
|
restartPolicy runconfig.RestartPolicy
|
2014-08-05 01:20:53 +00:00
|
|
|
|
|
|
|
// failureCount is the number of times the container has failed to
|
|
|
|
// start in a row
|
|
|
|
failureCount int
|
|
|
|
|
|
|
|
// shouldStop signals the monitor that the next time the container exits it is
|
|
|
|
// either because docker or the user asked for the container to be stopped
|
|
|
|
shouldStop bool
|
|
|
|
|
2014-08-13 21:56:35 +00:00
|
|
|
// startSignal is a channel that is closes after the container initially starts
|
2014-08-13 01:03:11 +00:00
|
|
|
startSignal chan struct{}
|
|
|
|
|
2014-08-11 22:00:55 +00:00
|
|
|
// stopChan is used to signal to the monitor whenever there is a wait for the
|
|
|
|
// next restart so that the timeIncrement is not honored and the user is not
|
|
|
|
// left waiting for nothing to happen during this time
|
|
|
|
stopChan chan struct{}
|
|
|
|
|
2014-08-05 01:20:53 +00:00
|
|
|
// timeIncrement is the amount of time to wait between restarts
|
|
|
|
// this is in milliseconds
|
|
|
|
timeIncrement int
|
2014-08-12 20:08:26 +00:00
|
|
|
|
|
|
|
// lastStartTime is the time which the monitor last exec'd the container's process
|
|
|
|
lastStartTime time.Time
|
2014-08-05 00:05:56 +00:00
|
|
|
}
|
|
|
|
|
2014-08-13 01:03:11 +00:00
|
|
|
// newContainerMonitor returns an initialized containerMonitor for the provided container
|
|
|
|
// honoring the provided restart policy
|
2015-11-03 17:33:13 +00:00
|
|
|
func (daemon *Daemon) newContainerMonitor(container *Container, policy runconfig.RestartPolicy) *containerMonitor {
|
2014-08-05 00:05:56 +00:00
|
|
|
return &containerMonitor{
|
2015-11-03 17:33:13 +00:00
|
|
|
supervisor: daemon,
|
2014-08-05 00:05:56 +00:00
|
|
|
container: container,
|
|
|
|
restartPolicy: policy,
|
2014-08-05 01:20:53 +00:00
|
|
|
timeIncrement: defaultTimeIncrement,
|
2014-08-14 17:50:22 +00:00
|
|
|
stopChan: make(chan struct{}),
|
|
|
|
startSignal: make(chan struct{}),
|
2014-08-05 00:05:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop signals to the container monitor that it should stop monitoring the container
|
|
|
|
// for exits the next time the process dies
|
|
|
|
func (m *containerMonitor) ExitOnNext() {
|
|
|
|
m.mux.Lock()
|
2014-08-11 22:00:55 +00:00
|
|
|
|
|
|
|
// we need to protect having a double close of the channel when stop is called
|
|
|
|
// twice or else we will get a panic
|
|
|
|
if !m.shouldStop {
|
|
|
|
m.shouldStop = true
|
|
|
|
close(m.stopChan)
|
|
|
|
}
|
|
|
|
|
2014-08-05 00:05:56 +00:00
|
|
|
m.mux.Unlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close closes the container's resources such as networking allocations and
|
|
|
|
// unmounts the contatiner's root filesystem
|
2015-09-29 17:51:40 +00:00
|
|
|
func (m *containerMonitor) Close() error {
|
2014-08-05 00:05:56 +00:00
|
|
|
// Cleanup networking and mounts
|
2015-11-03 17:43:36 +00:00
|
|
|
m.supervisor.Cleanup(m.container)
|
2014-08-05 00:05:56 +00:00
|
|
|
|
2014-08-06 17:40:43 +00:00
|
|
|
// FIXME: here is race condition between two RUN instructions in Dockerfile
|
|
|
|
// because they share same runconfig and change image. Must be fixed
|
|
|
|
// in builder/builder.go
|
|
|
|
if err := m.container.toDisk(); err != nil {
|
2015-03-26 22:22:04 +00:00
|
|
|
logrus.Errorf("Error dumping container %s state to disk: %s", m.container.ID, err)
|
2014-08-06 17:40:43 +00:00
|
|
|
|
|
|
|
return err
|
2014-08-05 00:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start starts the containers process and monitors it according to the restart policy
|
2015-09-29 17:51:40 +00:00
|
|
|
func (m *containerMonitor) Start() error {
|
2014-08-05 00:05:56 +00:00
|
|
|
var (
|
2014-08-05 01:20:53 +00:00
|
|
|
err error
|
2014-10-30 23:06:54 +00:00
|
|
|
exitStatus execdriver.ExitStatus
|
2014-08-26 15:53:43 +00:00
|
|
|
// this variable indicates where we in execution flow:
|
|
|
|
// before Run or after
|
|
|
|
afterRun bool
|
2014-08-05 00:05:56 +00:00
|
|
|
)
|
2014-08-05 01:20:53 +00:00
|
|
|
|
|
|
|
// ensure that when the monitor finally exits we release the networking and unmount the rootfs
|
2014-08-14 11:51:31 +00:00
|
|
|
defer func() {
|
2014-08-26 15:53:43 +00:00
|
|
|
if afterRun {
|
2014-08-14 11:51:31 +00:00
|
|
|
m.container.Lock()
|
|
|
|
defer m.container.Unlock()
|
2015-11-11 03:28:23 +00:00
|
|
|
m.container.setStopped(&exitStatus)
|
2014-08-14 11:51:31 +00:00
|
|
|
}
|
2015-09-29 17:51:40 +00:00
|
|
|
m.Close()
|
2014-08-14 11:51:31 +00:00
|
|
|
}()
|
2015-08-05 21:09:08 +00:00
|
|
|
// reset stopped flag
|
|
|
|
if m.container.HasBeenManuallyStopped {
|
|
|
|
m.container.HasBeenManuallyStopped = false
|
|
|
|
}
|
2014-08-05 00:05:56 +00:00
|
|
|
|
|
|
|
// reset the restart count
|
|
|
|
m.container.RestartCount = -1
|
|
|
|
|
2014-08-11 22:00:55 +00:00
|
|
|
for {
|
2014-08-05 00:05:56 +00:00
|
|
|
m.container.RestartCount++
|
2014-08-05 01:20:53 +00:00
|
|
|
|
2015-11-03 18:45:12 +00:00
|
|
|
if err := m.supervisor.StartLogging(m.container); err != nil {
|
2014-08-28 11:39:27 +00:00
|
|
|
m.resetContainer(false)
|
2014-08-05 00:05:56 +00:00
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-08-26 22:44:00 +00:00
|
|
|
pipes := execdriver.NewPipes(m.container.stdin, m.container.stdout, m.container.stderr, m.container.Config.OpenStdin)
|
2014-08-05 00:05:56 +00:00
|
|
|
|
2015-11-03 17:33:13 +00:00
|
|
|
m.logEvent("start")
|
2014-08-07 17:50:25 +00:00
|
|
|
|
2014-08-12 20:08:26 +00:00
|
|
|
m.lastStartTime = time.Now()
|
|
|
|
|
2015-11-03 19:25:22 +00:00
|
|
|
if exitStatus, err = m.supervisor.Run(m.container, pipes, m.callback); err != nil {
|
2014-08-13 01:03:11 +00:00
|
|
|
// if we receive an internal error from the initial start of a container then lets
|
|
|
|
// return it instead of entering the restart loop
|
2015-11-09 02:29:34 +00:00
|
|
|
// set to 127 for container cmd not found/does not exist)
|
2015-07-29 12:21:16 +00:00
|
|
|
if strings.Contains(err.Error(), "executable file not found") ||
|
|
|
|
strings.Contains(err.Error(), "no such file or directory") ||
|
|
|
|
strings.Contains(err.Error(), "system cannot find the file specified") {
|
|
|
|
if m.container.RestartCount == 0 {
|
|
|
|
m.container.ExitCode = 127
|
|
|
|
m.resetContainer(false)
|
|
|
|
return derr.ErrorCodeCmdNotFound
|
|
|
|
}
|
|
|
|
}
|
2015-11-09 02:29:34 +00:00
|
|
|
// set to 126 for container cmd can't be invoked errors
|
2015-07-29 12:21:16 +00:00
|
|
|
if strings.Contains(err.Error(), syscall.EACCES.Error()) {
|
|
|
|
if m.container.RestartCount == 0 {
|
|
|
|
m.container.ExitCode = 126
|
|
|
|
m.resetContainer(false)
|
|
|
|
return derr.ErrorCodeCmdCouldNotBeInvoked
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-13 21:58:57 +00:00
|
|
|
if m.container.RestartCount == 0 {
|
2014-10-30 23:06:54 +00:00
|
|
|
m.container.ExitCode = -1
|
2014-08-28 11:39:27 +00:00
|
|
|
m.resetContainer(false)
|
2014-08-13 01:03:11 +00:00
|
|
|
|
2015-11-05 17:01:18 +00:00
|
|
|
return derr.ErrorCodeCantStart.WithArgs(m.container.ID, utils.GetErrorMessage(err))
|
2014-08-13 01:03:11 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 22:22:04 +00:00
|
|
|
logrus.Errorf("Error running container: %s", err)
|
2014-08-05 00:05:56 +00:00
|
|
|
}
|
|
|
|
|
2014-08-14 11:51:31 +00:00
|
|
|
// here container.Lock is already lost
|
2014-08-26 15:53:43 +00:00
|
|
|
afterRun = true
|
2014-08-14 11:51:31 +00:00
|
|
|
|
2014-10-08 17:03:57 +00:00
|
|
|
m.resetMonitor(err == nil && exitStatus.ExitCode == 0)
|
2014-08-05 00:05:56 +00:00
|
|
|
|
2014-10-08 17:03:57 +00:00
|
|
|
if m.shouldRestart(exitStatus.ExitCode) {
|
2015-07-30 21:01:53 +00:00
|
|
|
m.container.setRestarting(&exitStatus)
|
2015-11-03 17:33:13 +00:00
|
|
|
m.logEvent("die")
|
2014-08-28 11:39:27 +00:00
|
|
|
m.resetContainer(true)
|
2014-08-11 18:07:37 +00:00
|
|
|
|
2014-08-11 17:50:02 +00:00
|
|
|
// sleep with a small time increment between each restart to help avoid issues cased by quickly
|
|
|
|
// restarting the container because of some types of errors ( networking cut out, etc... )
|
2014-08-11 22:00:55 +00:00
|
|
|
m.waitForNextRestart()
|
|
|
|
|
|
|
|
// we need to check this before reentering the loop because the waitForNextRestart could have
|
|
|
|
// been terminated by a request from a user
|
|
|
|
if m.shouldStop {
|
|
|
|
return err
|
|
|
|
}
|
2014-08-05 00:05:56 +00:00
|
|
|
continue
|
|
|
|
}
|
2015-09-11 10:01:47 +00:00
|
|
|
|
2015-11-03 17:33:13 +00:00
|
|
|
m.logEvent("die")
|
2014-08-28 11:39:27 +00:00
|
|
|
m.resetContainer(true)
|
2014-08-26 15:53:43 +00:00
|
|
|
return err
|
2014-08-11 22:00:55 +00:00
|
|
|
}
|
2014-08-05 00:05:56 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 18:07:37 +00:00
|
|
|
// resetMonitor resets the stateful fields on the containerMonitor based on the
|
2015-03-13 09:12:02 +00:00
|
|
|
// previous runs success or failure. Regardless of success, if the container had
|
2014-08-12 20:08:26 +00:00
|
|
|
// an execution time of more than 10s then reset the timer back to the default
|
2014-08-11 18:07:37 +00:00
|
|
|
func (m *containerMonitor) resetMonitor(successful bool) {
|
2014-08-12 20:08:26 +00:00
|
|
|
executionTime := time.Now().Sub(m.lastStartTime).Seconds()
|
|
|
|
|
|
|
|
if executionTime > 10 {
|
2014-08-11 18:07:37 +00:00
|
|
|
m.timeIncrement = defaultTimeIncrement
|
|
|
|
} else {
|
|
|
|
// otherwise we need to increment the amount of time we wait before restarting
|
|
|
|
// the process. We will build up by multiplying the increment by 2
|
2014-08-12 20:08:26 +00:00
|
|
|
m.timeIncrement *= 2
|
|
|
|
}
|
2014-08-11 18:07:37 +00:00
|
|
|
|
2014-08-12 20:08:26 +00:00
|
|
|
// the container exited successfully so we need to reset the failure counter
|
|
|
|
if successful {
|
|
|
|
m.failureCount = 0
|
|
|
|
} else {
|
2014-08-11 18:07:37 +00:00
|
|
|
m.failureCount++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-11 22:00:55 +00:00
|
|
|
// waitForNextRestart waits with the default time increment to restart the container unless
|
2014-08-13 21:56:35 +00:00
|
|
|
// a user or docker asks for the container to be stopped
|
2014-08-11 22:00:55 +00:00
|
|
|
func (m *containerMonitor) waitForNextRestart() {
|
|
|
|
select {
|
|
|
|
case <-time.After(time.Duration(m.timeIncrement) * time.Millisecond):
|
|
|
|
case <-m.stopChan:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-05 01:20:53 +00:00
|
|
|
// shouldRestart checks the restart policy and applies the rules to determine if
|
|
|
|
// the container's process should be restarted
|
2014-10-08 17:03:57 +00:00
|
|
|
func (m *containerMonitor) shouldRestart(exitCode int) bool {
|
2014-08-05 00:05:56 +00:00
|
|
|
m.mux.Lock()
|
2014-08-05 01:20:53 +00:00
|
|
|
defer m.mux.Unlock()
|
|
|
|
|
|
|
|
// do not restart if the user or docker has requested that this container be stopped
|
|
|
|
if m.shouldStop {
|
2015-11-03 19:25:22 +00:00
|
|
|
m.container.HasBeenManuallyStopped = !m.supervisor.IsShuttingDown()
|
2014-08-05 01:20:53 +00:00
|
|
|
return false
|
|
|
|
}
|
2014-08-05 00:05:56 +00:00
|
|
|
|
2015-05-16 11:34:09 +00:00
|
|
|
switch {
|
2015-08-05 21:09:08 +00:00
|
|
|
case m.restartPolicy.IsAlways(), m.restartPolicy.IsUnlessStopped():
|
2014-08-05 01:20:53 +00:00
|
|
|
return true
|
2015-05-16 11:34:09 +00:00
|
|
|
case m.restartPolicy.IsOnFailure():
|
2014-08-05 01:20:53 +00:00
|
|
|
// the default value of 0 for MaximumRetryCount means that we will not enforce a maximum count
|
2015-01-07 07:16:04 +00:00
|
|
|
if max := m.restartPolicy.MaximumRetryCount; max != 0 && m.failureCount > max {
|
2015-03-26 22:22:04 +00:00
|
|
|
logrus.Debugf("stopping restart of container %s because maximum failure could of %d has been reached",
|
2015-03-24 11:25:26 +00:00
|
|
|
stringid.TruncateID(m.container.ID), max)
|
2014-08-05 01:20:53 +00:00
|
|
|
return false
|
|
|
|
}
|
2014-08-05 00:05:56 +00:00
|
|
|
|
2014-10-08 17:03:57 +00:00
|
|
|
return exitCode != 0
|
2014-08-05 01:20:53 +00:00
|
|
|
}
|
2014-08-05 00:05:56 +00:00
|
|
|
|
2014-08-05 01:20:53 +00:00
|
|
|
return false
|
2014-08-05 00:05:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// callback ensures that the container's state is properly updated after we
|
|
|
|
// received ack from the execution drivers
|
2015-09-29 17:51:40 +00:00
|
|
|
func (m *containerMonitor) callback(processConfig *execdriver.ProcessConfig, pid int, chOOM <-chan struct{}) error {
|
2015-09-11 10:01:47 +00:00
|
|
|
go func() {
|
|
|
|
_, ok := <-chOOM
|
|
|
|
if ok {
|
2015-11-03 17:33:13 +00:00
|
|
|
m.logEvent("oom")
|
2015-09-11 10:01:47 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2014-08-26 22:05:37 +00:00
|
|
|
if processConfig.Tty {
|
2014-08-05 00:05:56 +00:00
|
|
|
// The callback is called after the process Start()
|
2014-09-28 15:01:35 +00:00
|
|
|
// so we are in the parent process. In TTY mode, stdin/out/err is the PtySlave
|
2014-08-05 00:05:56 +00:00
|
|
|
// which we close here.
|
2014-08-26 22:05:37 +00:00
|
|
|
if c, ok := processConfig.Stdout.(io.Closer); ok {
|
2014-08-05 00:05:56 +00:00
|
|
|
c.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-31 15:20:35 +00:00
|
|
|
m.container.setRunning(pid)
|
2014-08-05 00:05:56 +00:00
|
|
|
|
2014-08-14 07:01:39 +00:00
|
|
|
// signal that the process has started
|
|
|
|
// close channel only if not closed
|
|
|
|
select {
|
|
|
|
case <-m.startSignal:
|
|
|
|
default:
|
2014-08-13 21:56:35 +00:00
|
|
|
close(m.startSignal)
|
|
|
|
}
|
2014-08-13 01:03:11 +00:00
|
|
|
|
2015-07-30 21:01:53 +00:00
|
|
|
if err := m.container.toDiskLocking(); err != nil {
|
2015-07-02 10:24:35 +00:00
|
|
|
logrus.Errorf("Error saving container to disk: %v", err)
|
2014-08-05 00:05:56 +00:00
|
|
|
}
|
2015-09-11 19:05:57 +00:00
|
|
|
return nil
|
2014-08-05 00:05:56 +00:00
|
|
|
}
|
2014-08-11 18:07:37 +00:00
|
|
|
|
|
|
|
// resetContainer resets the container's IO and ensures that the command is able to be executed again
|
|
|
|
// by copying the data into a new struct
|
2014-08-28 11:39:27 +00:00
|
|
|
// if lock is true, then container locked during reset
|
|
|
|
func (m *containerMonitor) resetContainer(lock bool) {
|
2014-08-11 18:07:37 +00:00
|
|
|
container := m.container
|
2014-08-28 11:39:27 +00:00
|
|
|
if lock {
|
|
|
|
container.Lock()
|
|
|
|
defer container.Unlock()
|
|
|
|
}
|
2014-08-11 18:07:37 +00:00
|
|
|
|
|
|
|
if container.Config.OpenStdin {
|
2014-08-26 22:44:00 +00:00
|
|
|
if err := container.stdin.Close(); err != nil {
|
2015-03-26 22:22:04 +00:00
|
|
|
logrus.Errorf("%s: Error close stdin: %s", container.ID, err)
|
2014-08-11 18:07:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-26 22:44:00 +00:00
|
|
|
if err := container.stdout.Clean(); err != nil {
|
2015-03-26 22:22:04 +00:00
|
|
|
logrus.Errorf("%s: Error close stdout: %s", container.ID, err)
|
2014-08-11 18:07:37 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 22:44:00 +00:00
|
|
|
if err := container.stderr.Clean(); err != nil {
|
2015-03-26 22:22:04 +00:00
|
|
|
logrus.Errorf("%s: Error close stderr: %s", container.ID, err)
|
2014-08-11 18:07:37 +00:00
|
|
|
}
|
|
|
|
|
2014-08-26 22:05:37 +00:00
|
|
|
if container.command != nil && container.command.ProcessConfig.Terminal != nil {
|
|
|
|
if err := container.command.ProcessConfig.Terminal.Close(); err != nil {
|
2015-03-26 22:22:04 +00:00
|
|
|
logrus.Errorf("%s: Error closing terminal: %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 {
|
2014-08-26 22:44:00 +00:00
|
|
|
container.stdin, container.stdinPipe = io.Pipe()
|
2014-08-11 18:07:37 +00:00
|
|
|
}
|
|
|
|
|
2015-02-04 19:04:58 +00:00
|
|
|
if container.logDriver != nil {
|
2015-03-18 18:44:14 +00:00
|
|
|
if container.logCopier != nil {
|
|
|
|
exit := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
container.logCopier.Wait()
|
|
|
|
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-02-04 19:04:58 +00:00
|
|
|
container.logDriver.Close()
|
2015-03-18 18:44:14 +00:00
|
|
|
container.logCopier = nil
|
2015-02-04 19:04:58 +00:00
|
|
|
container.logDriver = nil
|
|
|
|
}
|
|
|
|
|
2014-08-26 22:05:37 +00:00
|
|
|
c := container.command.ProcessConfig.Cmd
|
2014-08-11 18:07:37 +00:00
|
|
|
|
2014-08-26 22:05:37 +00:00
|
|
|
container.command.ProcessConfig.Cmd = exec.Cmd{
|
2014-08-11 18:07:37 +00:00
|
|
|
Stdin: c.Stdin,
|
|
|
|
Stdout: c.Stdout,
|
|
|
|
Stderr: c.Stderr,
|
|
|
|
Path: c.Path,
|
|
|
|
Env: c.Env,
|
|
|
|
ExtraFiles: c.ExtraFiles,
|
|
|
|
Args: c.Args,
|
|
|
|
Dir: c.Dir,
|
|
|
|
SysProcAttr: c.SysProcAttr,
|
|
|
|
}
|
|
|
|
}
|
2015-11-03 17:33:13 +00:00
|
|
|
|
|
|
|
func (m *containerMonitor) logEvent(action string) {
|
|
|
|
m.supervisor.LogContainerEvent(m.container, action)
|
|
|
|
}
|