2015-05-02 04:03:35 +03:00
|
|
|
package daemon
|
|
|
|
|
2015-09-18 20:48:16 +03:00
|
|
|
import (
|
|
|
|
derr "github.com/docker/docker/errors"
|
|
|
|
)
|
2015-05-02 04:03:35 +03:00
|
|
|
|
|
|
|
// ContainerPause pauses a container
|
2015-09-29 20:51:40 +03:00
|
|
|
func (daemon *Daemon) ContainerPause(name string) error {
|
|
|
|
container, err := daemon.Get(name)
|
2015-05-02 04:03:35 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-11-03 02:39:39 +03:00
|
|
|
if err := daemon.containerPause(container); err != nil {
|
2015-09-18 20:48:16 +03:00
|
|
|
return derr.ErrorCodePauseError.WithArgs(name, err)
|
2015-05-02 04:03:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2015-11-03 02:39:39 +03:00
|
|
|
|
|
|
|
// 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
|
2015-11-03 20:33:13 +03:00
|
|
|
daemon.LogContainerEvent(container, "pause")
|
2015-11-03 02:39:39 +03:00
|
|
|
return nil
|
|
|
|
}
|