diff options
Diffstat (limited to 'libpod/container.go')
-rw-r--r-- | libpod/container.go | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/libpod/container.go b/libpod/container.go index adc52d85f..ce4d6ea84 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -424,16 +424,6 @@ func (c *Container) refresh() error { } c.state.RunDir = dir - // The container is no longer mounted - c.state.Mounted = false - c.state.Mountpoint = "" - - // The container is no longer running - c.state.PID = 0 - - // The container no longer exists in runc - c.state.State = ContainerStateConfigured - if err := c.runtime.state.SaveContainer(c); err != nil { return errors.Wrapf(err, "error refreshing state for container %s", c.ID()) } @@ -458,35 +448,40 @@ func (c *Container) Init() (err error) { return err } - // Save the OCI spec to disk + // If the OCI spec already exists, we need to replace it + // Cannot guarantee some things, e.g. network namespaces, have the same + // paths jsonPath := filepath.Join(c.bundlePath(), "config.json") if _, err := os.Stat(jsonPath); err != nil { if !os.IsNotExist(err) { return errors.Wrapf(err, "error doing stat on container %s spec", c.ID()) } - - // The spec does not exist, needs to be created - g := generate.NewFromSpec(c.config.Spec) - // Mount ShmDir from host into container - g.AddBindMount(c.config.ShmDir, "/dev/shm", []string{"rw"}) - c.runningSpec = g.Spec() - c.runningSpec.Root.Path = c.state.Mountpoint - c.runningSpec.Annotations[crioAnnotations.Created] = c.config.CreatedTime.Format(time.RFC3339Nano) - c.runningSpec.Annotations["org.opencontainers.image.stopSignal"] = fmt.Sprintf("%d", c.config.StopSignal) - - fileJSON, err := json.Marshal(c.runningSpec) - if err != nil { - return errors.Wrapf(err, "error exporting runtime spec for container %s to JSON", c.ID()) - } - if err := ioutil.WriteFile(jsonPath, fileJSON, 0644); err != nil { - return errors.Wrapf(err, "error writing runtime spec JSON to file for container %s", c.ID()) + // The spec does not exist, we're fine + } else { + // The spec exists, need to remove it + if err := os.Remove(jsonPath); err != nil { + return errors.Wrapf(err, "error replacing runtime spec for container %s", c.ID()) } + } - logrus.Debugf("Created OCI spec for container %s at %s", c.ID(), jsonPath) - } else { - // The spec exists - logrus.Debugf("Using existing OCI spec for container %s at %s", c.ID(), jsonPath) + // Save OCI spec to disk + g := generate.NewFromSpec(c.config.Spec) + // Mount ShmDir from host into container + g.AddBindMount(c.config.ShmDir, "/dev/shm", []string{"rw"}) + c.runningSpec = g.Spec() + c.runningSpec.Root.Path = c.state.Mountpoint + c.runningSpec.Annotations[crioAnnotations.Created] = c.config.CreatedTime.Format(time.RFC3339Nano) + c.runningSpec.Annotations["org.opencontainers.image.stopSignal"] = fmt.Sprintf("%d", c.config.StopSignal) + + fileJSON, err := json.Marshal(c.runningSpec) + if err != nil { + return errors.Wrapf(err, "error exporting runtime spec for container %s to JSON", c.ID()) } + if err := ioutil.WriteFile(jsonPath, fileJSON, 0644); err != nil { + return errors.Wrapf(err, "error writing runtime spec JSON to file for container %s", c.ID()) + } + + logrus.Debugf("Created OCI spec for container %s at %s", c.ID(), jsonPath) c.state.ConfigPath = jsonPath |