|
@@ -1,6 +1,7 @@
|
|
package daemon // import "github.com/docker/docker/daemon"
|
|
package daemon // import "github.com/docker/docker/daemon"
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "context"
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
|
containertypes "github.com/docker/docker/api/types/container"
|
|
containertypes "github.com/docker/docker/api/types/container"
|
|
@@ -14,12 +15,12 @@ import (
|
|
// timeout, ContainerRestart will wait forever until a graceful
|
|
// timeout, ContainerRestart will wait forever until a graceful
|
|
// stop. Returns an error if the container cannot be found, or if
|
|
// stop. Returns an error if the container cannot be found, or if
|
|
// there is an underlying error at any stage of the restart.
|
|
// there is an underlying error at any stage of the restart.
|
|
-func (daemon *Daemon) ContainerRestart(name string, seconds *int) error {
|
|
|
|
|
|
+func (daemon *Daemon) ContainerRestart(ctx context.Context, name string, options containertypes.StopOptions) error {
|
|
ctr, err := daemon.GetContainer(name)
|
|
ctr, err := daemon.GetContainer(name)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- err = daemon.containerRestart(ctr, seconds)
|
|
|
|
|
|
+ err = daemon.containerRestart(ctx, ctr, options)
|
|
if err != nil {
|
|
if err != nil {
|
|
return fmt.Errorf("Cannot restart container %s: %v", name, err)
|
|
return fmt.Errorf("Cannot restart container %s: %v", name, err)
|
|
}
|
|
}
|
|
@@ -31,7 +32,7 @@ func (daemon *Daemon) ContainerRestart(name string, seconds *int) error {
|
|
// container. When stopping, wait for the given duration in seconds to
|
|
// container. When stopping, wait for the given duration in seconds to
|
|
// gracefully stop, before forcefully terminating the container. If
|
|
// gracefully stop, before forcefully terminating the container. If
|
|
// given a negative duration, wait forever for a graceful stop.
|
|
// given a negative duration, wait forever for a graceful stop.
|
|
-func (daemon *Daemon) containerRestart(container *container.Container, seconds *int) error {
|
|
|
|
|
|
+func (daemon *Daemon) containerRestart(ctx context.Context, container *container.Container, options containertypes.StopOptions) error {
|
|
// Determine isolation. If not specified in the hostconfig, use daemon default.
|
|
// Determine isolation. If not specified in the hostconfig, use daemon default.
|
|
actualIsolation := container.HostConfig.Isolation
|
|
actualIsolation := container.HostConfig.Isolation
|
|
if containertypes.Isolation.IsDefault(actualIsolation) {
|
|
if containertypes.Isolation.IsDefault(actualIsolation) {
|
|
@@ -56,7 +57,7 @@ func (daemon *Daemon) containerRestart(container *container.Container, seconds *
|
|
autoRemove := container.HostConfig.AutoRemove
|
|
autoRemove := container.HostConfig.AutoRemove
|
|
|
|
|
|
container.HostConfig.AutoRemove = false
|
|
container.HostConfig.AutoRemove = false
|
|
- err := daemon.containerStop(container, seconds)
|
|
|
|
|
|
+ err := daemon.containerStop(ctx, container, options)
|
|
// restore AutoRemove irrespective of whether the stop worked or not
|
|
// restore AutoRemove irrespective of whether the stop worked or not
|
|
container.HostConfig.AutoRemove = autoRemove
|
|
container.HostConfig.AutoRemove = autoRemove
|
|
// containerStop will write HostConfig to disk, we shall restore AutoRemove
|
|
// containerStop will write HostConfig to disk, we shall restore AutoRemove
|