mirror of
https://github.com/containers/podman.git
synced 2025-05-20 00:27:03 +08:00
Merge pull request #11878 from mheon/stop_stopping
Allow `podman stop` to be run on Stopping containers
This commit is contained in:
@ -184,7 +184,7 @@ func (c *Container) StopWithTimeout(timeout uint) error {
|
|||||||
return define.ErrCtrStopped
|
return define.ErrCtrStopped
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.ensureState(define.ContainerStateCreated, define.ContainerStateRunning) {
|
if !c.ensureState(define.ContainerStateCreated, define.ContainerStateRunning, define.ContainerStateStopping) {
|
||||||
return errors.Wrapf(define.ErrCtrStateInvalid, "can only stop created or running containers. %s is in state %s", c.ID(), c.state.State.String())
|
return errors.Wrapf(define.ErrCtrStateInvalid, "can only stop created or running containers. %s is in state %s", c.ID(), c.state.State.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -690,7 +690,7 @@ func (c *Container) Sync() error {
|
|||||||
|
|
||||||
// If runtime knows about the container, update its status in runtime
|
// If runtime knows about the container, update its status in runtime
|
||||||
// And then save back to disk
|
// And then save back to disk
|
||||||
if c.ensureState(define.ContainerStateCreated, define.ContainerStateRunning, define.ContainerStatePaused, define.ContainerStateStopped) {
|
if c.ensureState(define.ContainerStateCreated, define.ContainerStateRunning, define.ContainerStatePaused, define.ContainerStateStopped, define.ContainerStateStopping) {
|
||||||
oldState := c.state.State
|
oldState := c.state.State
|
||||||
if err := c.ociRuntime.UpdateContainerStatus(c); err != nil {
|
if err := c.ociRuntime.UpdateContainerStatus(c); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -351,6 +351,12 @@ func (r *ConmonOCIRuntime) UpdateContainerStatus(ctr *Container) error {
|
|||||||
return ctr.handleExitFile(exitFile, fi)
|
return ctr.handleExitFile(exitFile, fi)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle ContainerStateStopping - keep it unless the container
|
||||||
|
// transitioned to no longer running.
|
||||||
|
if oldState == define.ContainerStateStopping && (ctr.state.State == define.ContainerStatePaused || ctr.state.State == define.ContainerStateRunning) {
|
||||||
|
ctr.state.State = define.ContainerStateStopping
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,6 +136,12 @@ func ListContainerBatch(rt *libpod.Runtime, ctr *libpod.Container, opts entities
|
|||||||
)
|
)
|
||||||
|
|
||||||
batchErr := ctr.Batch(func(c *libpod.Container) error {
|
batchErr := ctr.Batch(func(c *libpod.Container) error {
|
||||||
|
if opts.Sync {
|
||||||
|
if err := c.Sync(); err != nil {
|
||||||
|
return errors.Wrapf(err, "unable to update container state from OCI runtime")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
conConfig = c.Config()
|
conConfig = c.Config()
|
||||||
conState, err = c.State()
|
conState, err = c.State()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user