mirror of
https://github.com/containers/podman.git
synced 2025-10-19 20:23:08 +08:00
Do not require Init() before Start()
This will help dependency races Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #577 Approved by: rhatdan
This commit is contained in:
@ -48,7 +48,9 @@ func (c *Container) Init() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start starts a container
|
// Start starts a container
|
||||||
// Start can start created or stopped containers
|
// Start can start configured, created or stopped containers
|
||||||
|
// For configured containers, the container will be initialized first, then
|
||||||
|
// started
|
||||||
// Stopped containers will be deleted and re-created in runc, undergoing a fresh
|
// Stopped containers will be deleted and re-created in runc, undergoing a fresh
|
||||||
// Init()
|
// Init()
|
||||||
func (c *Container) Start() (err error) {
|
func (c *Container) Start() (err error) {
|
||||||
@ -62,7 +64,9 @@ func (c *Container) Start() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Container must be created or stopped to be started
|
// Container must be created or stopped to be started
|
||||||
if !(c.state.State == ContainerStateCreated || c.state.State == ContainerStateStopped) {
|
if !(c.state.State == ContainerStateConfigured ||
|
||||||
|
c.state.State == ContainerStateCreated ||
|
||||||
|
c.state.State == ContainerStateStopped) {
|
||||||
return errors.Wrapf(ErrCtrStateInvalid, "container %s must be in Created or Stopped state to be started", c.ID())
|
return errors.Wrapf(ErrCtrStateInvalid, "container %s must be in Created or Stopped state to be started", c.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,11 +81,16 @@ func (c *Container) Start() (err error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Reinitialize the container if we need to
|
|
||||||
if c.state.State == ContainerStateStopped {
|
if c.state.State == ContainerStateStopped {
|
||||||
|
// Reinitialize the container if we need to
|
||||||
if err := c.reinit(); err != nil {
|
if err := c.reinit(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
} else if c.state.State == ContainerStateConfigured {
|
||||||
|
// Or initialize it for the first time if necessary
|
||||||
|
if err := c.init(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the container
|
// Start the container
|
||||||
@ -89,7 +98,9 @@ func (c *Container) Start() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StartAndAttach starts a container and attaches to it
|
// StartAndAttach starts a container and attaches to it
|
||||||
// StartAndAttach can start created or stopped containers
|
// StartAndAttach can start configured, created or stopped containers
|
||||||
|
// For configured containers, the container will be initialized first, then
|
||||||
|
// started
|
||||||
// Stopped containers will be deleted and re-created in runc, undergoing a fresh
|
// Stopped containers will be deleted and re-created in runc, undergoing a fresh
|
||||||
// Init()
|
// Init()
|
||||||
// If successful, an error channel will be returned containing the result of the
|
// If successful, an error channel will be returned containing the result of the
|
||||||
@ -107,7 +118,9 @@ func (c *Container) StartAndAttach(noStdin bool, keys string) (attachResChan <-c
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Container must be created or stopped to be started
|
// Container must be created or stopped to be started
|
||||||
if !(c.state.State == ContainerStateCreated || c.state.State == ContainerStateStopped) {
|
if !(c.state.State == ContainerStateConfigured ||
|
||||||
|
c.state.State == ContainerStateCreated ||
|
||||||
|
c.state.State == ContainerStateStopped) {
|
||||||
return nil, errors.Wrapf(ErrCtrStateInvalid, "container %s must be in Created or Stopped state to be started", c.ID())
|
return nil, errors.Wrapf(ErrCtrStateInvalid, "container %s must be in Created or Stopped state to be started", c.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,11 +135,16 @@ func (c *Container) StartAndAttach(noStdin bool, keys string) (attachResChan <-c
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Reinitialize the container if we need to
|
|
||||||
if c.state.State == ContainerStateStopped {
|
if c.state.State == ContainerStateStopped {
|
||||||
|
// Reinitialize the container if we need to
|
||||||
if err := c.reinit(); err != nil {
|
if err := c.reinit(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
} else if c.state.State == ContainerStateConfigured {
|
||||||
|
// Or initialize it for the first time if necessary
|
||||||
|
if err := c.init(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
attachChan := make(chan error)
|
attachChan := make(chan error)
|
||||||
|
Reference in New Issue
Block a user