diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2017-12-01 13:26:58 -0500 |
---|---|---|
committer | Matthew Heon <matthew.heon@gmail.com> | 2017-12-04 14:29:59 -0500 |
commit | ae5aac50aaacbdcc20e622e86f40c02136690fe7 (patch) | |
tree | caddca21e19f3bd0db2faa2c5783cff1836577f4 /libpod/runtime.go | |
parent | 750fc239b5da8e3f2792ae33f46a671ddf4622e3 (diff) | |
download | podman-ae5aac50aaacbdcc20e622e86f40c02136690fe7.tar.gz podman-ae5aac50aaacbdcc20e622e86f40c02136690fe7.tar.bz2 podman-ae5aac50aaacbdcc20e622e86f40c02136690fe7.zip |
Add handling for system restart in libpod
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Diffstat (limited to 'libpod/runtime.go')
-rw-r--r-- | libpod/runtime.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/libpod/runtime.go b/libpod/runtime.go index b86e06546..7997679e2 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -173,6 +173,24 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) { runtime.state = state } + // We now need to see if the system has restarted + // We check for the presence of a file in our tmp directory to verify this + runtimeAliveFile := filepath.Join(runtime.config.TmpDir, "alive") + _, err = os.Stat(runtimeAliveFile) + if err != nil { + // If the file doesn't exist, we need to refresh the state + // This will trigger on first use as well, but refreshing an + // empty state only creates a single file + // As such, it's not really a performance concern + if os.IsNotExist(err) { + if err2 := runtime.refresh(runtimeAliveFile); err2 != nil { + return nil, err2 + } + } else { + return nil, errors.Wrapf(err, "error reading runtime status file %s", runtimeAliveFile) + } + } + // Mark the runtime as valid - ready to be used, cannot be modified // further runtime.valid = true @@ -238,3 +256,30 @@ func (r *Runtime) Shutdown(force bool) error { return lastError } + +// Reconfigures the runtime after a reboot +// Refreshes the state, recreating temporary files +// Does not check validity as the runtime is not valid until after this has run +// TODO: there's a potential race here, where multiple libpods could be in this +// function before the runtime ready file is created +// This probably doesn't matter as the actual container operations are locked +func (r *Runtime) refresh(alivePath string) error { + // We need to refresh the state of all containers + ctrs, err := r.state.AllContainers() + if err != nil { + return errors.Wrapf(err, "error retrieving all containers from state") + } + for _, ctr := range ctrs { + if err := ctr.refresh(); err != nil { + return err + } + } + + file, err := os.OpenFile(alivePath, os.O_RDONLY|os.O_CREATE, 0644) + if err != nil { + return errors.Wrapf(err, "error creating runtime status file %s", alivePath) + } + defer file.Close() + + return nil +} |