2015-05-01 21:03:35 -04:00
|
|
|
package daemon
|
|
|
|
|
2015-09-18 13:48:16 -04:00
|
|
|
import (
|
2015-11-12 14:55:17 -05:00
|
|
|
"github.com/docker/docker/container"
|
2015-09-18 13:48:16 -04:00
|
|
|
derr "github.com/docker/docker/errors"
|
|
|
|
)
|
2015-05-01 21:03:35 -04:00
|
|
|
|
|
|
|
// ContainerPause pauses a container
|
2015-09-29 13:51:40 -04:00
|
|
|
func (daemon *Daemon) ContainerPause(name string) error {
|
2015-12-11 12:39:28 -05:00
|
|
|
container, err := daemon.GetContainer(name)
|
2015-05-01 21:03:35 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-11-02 18:39:39 -05:00
|
|
|
if err := daemon.containerPause(container); err != nil {
|
2015-09-18 13:48:16 -04:00
|
|
|
return derr.ErrorCodePauseError.WithArgs(name, err)
|
2015-05-01 21:03:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2015-11-02 18:39:39 -05:00
|
|
|
|
|
|
|
// containerPause pauses the container execution without stopping the process.
|
|
|
|
// The execution can be resumed by calling containerUnpause.
|
2015-11-12 14:55:17 -05:00
|
|
|
func (daemon *Daemon) containerPause(container *container.Container) error {
|
2015-11-02 18:39:39 -05:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2015-11-12 14:55:17 -05:00
|
|
|
if err := daemon.execDriver.Pause(container.Command); err != nil {
|
2015-11-02 18:39:39 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
container.Paused = true
|
2015-11-03 12:33:13 -05:00
|
|
|
daemon.LogContainerEvent(container, "pause")
|
2015-11-02 18:39:39 -05:00
|
|
|
return nil
|
|
|
|
}
|