Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions containerm/mgr/mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (mgr *containerMgr) Stop(ctx context.Context, id string, stopOpts *types.St
}
container.Lock()
defer container.Unlock()
go mgr.applyRestartPolicy(context.Background(), container)
mgr.applyRestartPolicy(context.Background(), container)
return nil
}

Expand Down Expand Up @@ -312,10 +312,11 @@ func (mgr *containerMgr) Update(ctx context.Context, id string, updateOpts *type
changesMade = true
}

var rpChanged bool
if updateOpts.RestartPolicy != nil && !reflect.DeepEqual(updateOpts.RestartPolicy, container.HostConfig.RestartPolicy) {
mgr.resetContainerRestartManager(container, false)
container.HostConfig.RestartPolicy = updateOpts.RestartPolicy
changesMade = true
changesMade, rpChanged = true, true
}

if changesMade {
Expand All @@ -327,6 +328,10 @@ func (mgr *containerMgr) Update(ctx context.Context, id string, updateOpts *type
log.ErrorErr(errMeta, failedConfigStoringErrorMsg)
}
}

if rpChanged && (container.State.Exited || container.State.Status == types.Stopped) {
mgr.applyRestartPolicy(context.Background(), container)
}
return nil
}

Expand Down
13 changes: 8 additions & 5 deletions containerm/mgr/mgr_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (mgr *containerMgr) applyRestartPolicy(ctx context.Context, container *type
}
}
if err != nil {
mgr.updateConfigToStopped(ctx, container, -1, err)
mgr.updateConfigToStopped(ctx, container, -1, err, false)
}
}()
}
Expand Down Expand Up @@ -132,7 +132,7 @@ func (mgr *containerMgr) containersToArray() []*types.Container {
}
return ctrs
}
func (mgr *containerMgr) updateConfigToStopped(ctx context.Context, c *types.Container, exitCode int64, err error) error {
func (mgr *containerMgr) updateConfigToStopped(ctx context.Context, c *types.Container, exitCode int64, err error, releaseContainerResources bool) error {
var (
code int64
errMsg string
Expand All @@ -155,7 +155,10 @@ func (mgr *containerMgr) updateConfigToStopped(ctx context.Context, c *types.Con
}
}()

return mgr.releaseContainerResources(c)
if releaseContainerResources {
return mgr.releaseContainerResources(c)
}
return nil
}

func (mgr *containerMgr) updateConfigToExited(ctx context.Context, c *types.Container, exitCode int64, err error, oomKilled bool) error {
Expand Down Expand Up @@ -298,7 +301,7 @@ func (mgr *containerMgr) processStartContainer(ctx context.Context, id string, r

pid, err = mgr.ctrClient.StartContainer(ctx, container, "")
if err != nil {
_ = mgr.updateConfigToStopped(ctx, container, -1, err)
_ = mgr.updateConfigToStopped(ctx, container, -1, err, true)
return err
}

Expand Down Expand Up @@ -361,7 +364,7 @@ func (mgr *containerMgr) stopContainer(ctx context.Context, container *types.Con
container.ManuallyStopped = false
return exitErr
}
return mgr.updateConfigToStopped(ctx, container, exitCode, exitErr)
return mgr.updateConfigToStopped(ctx, container, exitCode, exitErr, true)
}

func (mgr *containerMgr) stopManagerService(ctx context.Context) error {
Expand Down