diff --git a/daemon/commit.go b/daemon/commit.go index d92c34ba5dce96e109f9f4fe6d81c4b5781bb5bf..fd11fc4683f755bd220842231414fc6ce997b44f 100644 --- a/daemon/commit.go +++ b/daemon/commit.go @@ -22,8 +22,8 @@ type ContainerCommitConfig struct { // The image can optionally be tagged into a repository. func (daemon *Daemon) Commit(container *Container, c *ContainerCommitConfig) (*image.Image, error) { if c.Pause && !container.isPaused() { - container.pause() - defer container.unpause() + daemon.containerPause(container) + defer daemon.containerUnpause(container) } rwTar, err := daemon.exportContainerRw(container) diff --git a/daemon/container.go b/daemon/container.go index f90dde799e72804dcbee2556e7de655351770ddc..b17429682a43518916a85e4b101fd77033b90cb7 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -343,50 +343,6 @@ func (container *Container) ExitOnNext() { container.monitor.ExitOnNext() } -func (container *Container) pause() error { - container.Lock() - defer container.Unlock() - - // We cannot Pause the container which is not running - if !container.Running { - return derr.ErrorCodeNotRunning.WithArgs(container.ID) - } - - // We cannot Pause the container which is already paused - if container.Paused { - return derr.ErrorCodeAlreadyPaused.WithArgs(container.ID) - } - - if err := container.daemon.execDriver.Pause(container.command); err != nil { - return err - } - container.Paused = true - container.logEvent("pause") - return nil -} - -func (container *Container) unpause() error { - container.Lock() - defer container.Unlock() - - // We cannot unpause the container which is not running - if !container.Running { - return derr.ErrorCodeNotRunning.WithArgs(container.ID) - } - - // We cannot unpause the container which is not paused - if !container.Paused { - return derr.ErrorCodeNotPaused.WithArgs(container.ID) - } - - if err := container.daemon.execDriver.Unpause(container.command); err != nil { - return err - } - container.Paused = false - container.logEvent("unpause") - return nil -} - // Resize changes the TTY of the process running inside the container // to the given height and width. The container must be running. func (container *Container) Resize(h, w int) error { diff --git a/daemon/daemon.go b/daemon/daemon.go index 138a56b7a3063af9155ff52ab140e4feac20d63b..ad1b2063fd9d6579ec6c04e761ebab6b32332037 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -849,10 +849,10 @@ func (daemon *Daemon) shutdownContainer(c *Container) error { if !ok { return fmt.Errorf("System doesn not support SIGTERM") } - if err := c.daemon.kill(c, int(sig)); err != nil { + if err := daemon.kill(c, int(sig)); err != nil { return fmt.Errorf("sending SIGTERM to container %s with error: %v", c.ID, err) } - if err := c.unpause(); err != nil { + if err := daemon.containerUnpause(c); err != nil { return fmt.Errorf("Failed to unpause container %s with error: %v", c.ID, err) } if _, err := c.WaitStop(10 * time.Second); err != nil { @@ -861,7 +861,7 @@ func (daemon *Daemon) shutdownContainer(c *Container) error { if !ok { return fmt.Errorf("System does not support SIGKILL") } - if err := c.daemon.kill(c, int(sig)); err != nil { + if err := daemon.kill(c, int(sig)); err != nil { logrus.Errorf("Failed to SIGKILL container %s", c.ID) } c.WaitStop(-1 * time.Second) diff --git a/daemon/pause.go b/daemon/pause.go index 385e93f9f97936c4a2a4d394f8bf4837eeae828d..4182e92e2fa7aacf212c3c78bb0fce669ed940b3 100644 --- a/daemon/pause.go +++ b/daemon/pause.go @@ -11,9 +11,33 @@ func (daemon *Daemon) ContainerPause(name string) error { return err } - if err := container.pause(); err != nil { + if err := daemon.containerPause(container); err != nil { return derr.ErrorCodePauseError.WithArgs(name, err) } return nil } + +// containerPause pauses the container execution without stopping the process. +// The execution can be resumed by calling containerUnpause. +func (daemon *Daemon) containerPause(container *Container) error { + container.Lock() + defer container.Unlock() + + // We cannot Pause the container which is not running + if !container.Running { + return derr.ErrorCodeNotRunning.WithArgs(container.ID) + } + + // We cannot Pause the container which is already paused + if container.Paused { + return derr.ErrorCodeAlreadyPaused.WithArgs(container.ID) + } + + if err := daemon.execDriver.Pause(container.command); err != nil { + return err + } + container.Paused = true + daemon.logContainerEvent(container, "pause") + return nil +} diff --git a/daemon/unpause.go b/daemon/unpause.go index 6dd41c511c0ca44f2132084e8936013586a779fe..4112494fc4145cc64f82051f50796108d569f278 100644 --- a/daemon/unpause.go +++ b/daemon/unpause.go @@ -11,9 +11,33 @@ func (daemon *Daemon) ContainerUnpause(name string) error { return err } - if err := container.unpause(); err != nil { + if err := daemon.containerUnpause(container); err != nil { return derr.ErrorCodeCantUnpause.WithArgs(name, err) } return nil } + +// containerUnpause resumes the container execution after the container is paused. +func (daemon *Daemon) containerUnpause(container *Container) error { + container.Lock() + defer container.Unlock() + + // We cannot unpause the container which is not running + if !container.Running { + return derr.ErrorCodeNotRunning.WithArgs(container.ID) + } + + // We cannot unpause the container which is not paused + if !container.Paused { + return derr.ErrorCodeNotPaused.WithArgs(container.ID) + } + + if err := daemon.execDriver.Unpause(container.command); err != nil { + return err + } + + container.Paused = false + daemon.logContainerEvent(container, "unpause") + return nil +}