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> Upstream-commit: ff3ea4c90f2ede5cccc6b49c4d2aad7201c91a4c Component: engine
This commit is contained in:
@@ -3,12 +3,12 @@
|
||||
package windows
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/docker/daemon/execdriver"
|
||||
)
|
||||
|
||||
// Update updates resource configs for a container.
|
||||
func (d *Driver) Update(c *execdriver.Command) error {
|
||||
return fmt.Errorf("Windows: Update not implemented")
|
||||
// Updating resource isn't supported on Windows
|
||||
// but we should return nil for enabling updating container
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ func (daemon *Daemon) containerStart(container *container.Container) (err error)
|
||||
}
|
||||
|
||||
func (daemon *Daemon) waitForStart(container *container.Container) error {
|
||||
return container.StartMonitor(daemon, container.HostConfig.RestartPolicy)
|
||||
return container.StartMonitor(daemon)
|
||||
}
|
||||
|
||||
// Cleanup releases any network resources allocated to the container along with any rules
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user