mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
Optionally init() during container restart
This allows us to restart containers that have never been started without error. This makes RestartWithTimeout work with running, stopped, and created containers. Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #719 Approved by: rhatdan
This commit is contained in:
@ -726,7 +726,7 @@ func (c *Container) RestartWithTimeout(ctx context.Context, timeout uint) error
|
|||||||
return errors.Wrapf(ErrCtrStateInvalid, "some dependencies of container %s are not started: %s", c.ID(), depString)
|
return errors.Wrapf(ErrCtrStateInvalid, "some dependencies of container %s are not started: %s", c.ID(), depString)
|
||||||
}
|
}
|
||||||
if c.state.State == ContainerStateUnknown || c.state.State == ContainerStatePaused {
|
if c.state.State == ContainerStateUnknown || c.state.State == ContainerStatePaused {
|
||||||
return errors.Errorf("unable to restart a container in a paused or unknown state")
|
return errors.Wrapf(ErrCtrStateInvalid, "unable to restart a container in a paused or unknown state")
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.state.State == ContainerStateRunning {
|
if c.state.State == ContainerStateRunning {
|
||||||
@ -737,7 +737,6 @@ func (c *Container) RestartWithTimeout(ctx context.Context, timeout uint) error
|
|||||||
if err := c.prepare(); err != nil {
|
if err := c.prepare(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err2 := c.cleanup(); err2 != nil {
|
if err2 := c.cleanup(); err2 != nil {
|
||||||
@ -751,6 +750,12 @@ func (c *Container) RestartWithTimeout(ctx context.Context, timeout uint) error
|
|||||||
if err := c.reinit(ctx); err != nil {
|
if err := c.reinit(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
} else if c.state.State == ContainerStateConfigured {
|
||||||
|
// Initialize the container if it has never been initialized
|
||||||
|
if err := c.init(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.start()
|
return c.start()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user