Update RestartPolicy of container

Add `--restart` flag for `update` command, so we can change restart
policy for a container no matter it's running or stopped.

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
This commit is contained in:
Zhang Wei
2016-01-04 23:58:20 +08:00
parent 6668326aa8
commit ff3ea4c90f
17 changed files with 154 additions and 33 deletions

View File

@@ -2,12 +2,13 @@ package daemon
import (
"fmt"
"time"
derr "github.com/docker/docker/errors"
"github.com/docker/engine-api/types/container"
)
// ContainerUpdate updates resources of the container
// ContainerUpdate updates configuration of the container
func (daemon *Daemon) ContainerUpdate(name string, hostConfig *container.HostConfig) ([]string, error) {
var warnings []string
@@ -58,11 +59,19 @@ func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) erro
return derr.ErrorCodeCantUpdate.WithArgs(container.ID, err.Error())
}
// if Restart Policy changed, we need to update container monitor
container.UpdateMonitor(hostConfig.RestartPolicy)
// if container is restarting, wait 5 seconds until it's running
if container.IsRestarting() {
container.WaitRunning(5 * time.Second)
}
// If container is not running, update hostConfig struct is enough,
// resources will be updated when the container is started again.
// If container is running (including paused), we need to update configs
// to the real world.
if container.IsRunning() {
if container.IsRunning() && !container.IsRestarting() {
if err := daemon.execDriver.Update(container.Command); err != nil {
return derr.ErrorCodeCantUpdate.WithArgs(container.ID, err.Error())
}