mirror of
https://github.com/containers/podman.git
synced 2025-08-06 03:19:52 +08:00
Implement container restarting
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #482 Approved by: baude
This commit is contained in:
@ -63,6 +63,9 @@ func (c *Container) Init() (err error) {
|
||||
}
|
||||
|
||||
// Start starts a container
|
||||
// Start can start created or stopped containers
|
||||
// Stopped containers will be deleted and re-created in runc, undergoing a fresh
|
||||
// Init()
|
||||
func (c *Container) Start() (err error) {
|
||||
if !c.locked {
|
||||
c.lock.Lock()
|
||||
@ -78,11 +81,6 @@ func (c *Container) Start() (err error) {
|
||||
return errors.Wrapf(ErrCtrStateInvalid, "container %s must be in Created or Stopped state to be started", c.ID())
|
||||
}
|
||||
|
||||
// TODO remove this when we patch conmon to support restarting containers
|
||||
if c.state.State == ContainerStateStopped {
|
||||
return errors.Wrapf(ErrNotImplemented, "restarting a stopped container is not yet supported")
|
||||
}
|
||||
|
||||
// Mount storage for the container if necessary
|
||||
if err := c.mountStorage(); err != nil {
|
||||
return err
|
||||
@ -109,6 +107,34 @@ func (c *Container) Start() (err error) {
|
||||
}
|
||||
}()
|
||||
|
||||
// Reinitialize the container if we need to
|
||||
if c.state.State == ContainerStateStopped {
|
||||
// If necessary, delete attach and ctl files
|
||||
if err := c.removeConmonFiles(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete the container in the runtime
|
||||
if err := c.runtime.ociRuntime.deleteContainer(c); err != nil {
|
||||
return errors.Wrapf(err, "error removing container %s from runtime", c.ID())
|
||||
}
|
||||
|
||||
// Our state is now Configured, as we've removed ourself from
|
||||
// the runtime
|
||||
// Set and save now to make sure that, if the init() below fails
|
||||
// we still have a valid state
|
||||
c.state.State = ContainerStateConfigured
|
||||
if err := c.save(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Reinitialize the container
|
||||
if err := c.init(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Start the container
|
||||
return c.start()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user