summaryrefslogtreecommitdiff
path: root/libpod/runtime.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2017-11-09 13:51:20 -0500
committerMatthew Heon <matthew.heon@gmail.com>2017-11-18 12:58:48 -0500
commit763e3726493c122d9722e0e294634ae8d78c426b (patch)
treea2b34450ab0dfe2131786315f393a1f7ca05ffdd /libpod/runtime.go
parentcb56716fc4bb632db84fab372fff8f5a9007ed3f (diff)
downloadpodman-763e3726493c122d9722e0e294634ae8d78c426b.tar.gz
podman-763e3726493c122d9722e0e294634ae8d78c426b.tar.bz2
podman-763e3726493c122d9722e0e294634ae8d78c426b.zip
Wire SQL backed state into rest of libpod
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Diffstat (limited to 'libpod/runtime.go')
-rw-r--r--libpod/runtime.go45
1 files changed, 37 insertions, 8 deletions
diff --git a/libpod/runtime.go b/libpod/runtime.go
index 80202c567..1bfb79947 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -2,6 +2,7 @@ package libpod
import (
"os"
+ "path/filepath"
"sync"
is "github.com/containers/image/storage"
@@ -35,6 +36,7 @@ type RuntimeConfig struct {
InsecureRegistries []string
Registries []string
SignaturePolicyPath string
+ InMemoryState bool
RuntimePath string
ConmonPath string
ConmonEnvVars []string
@@ -52,6 +54,7 @@ var (
// Leave this empty so containers/storage will use its defaults
StorageConfig: storage.StoreOptions{},
ImageDefaultTransport: "docker://",
+ InMemoryState: false,
RuntimePath: "/usr/bin/runc",
ConmonPath: "/usr/local/libexec/crio/conmon",
ConmonEnvVars: []string{
@@ -114,13 +117,6 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
SignaturePolicyPath: runtime.config.SignaturePolicyPath,
}
- // Set up the state
- state, err := NewInMemoryState()
- if err != nil {
- return nil, err
- }
- runtime.state = state
-
// Make an OCI runtime to perform container operations
ociRuntime, err := newOCIRuntime("runc", runtime.config.RuntimePath,
runtime.config.ConmonPath, runtime.config.ConmonEnvVars,
@@ -149,6 +145,34 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
}
}
+ // Set up the state
+ if runtime.config.InMemoryState {
+ state, err := NewInMemoryState()
+ if err != nil {
+ return nil, err
+ }
+ runtime.state = state
+ } else {
+ dbPath := filepath.Join(runtime.config.StaticDir, "state.sql")
+ lockPath := filepath.Join(runtime.config.TmpDir, "state.lck")
+ specsDir := filepath.Join(runtime.config.StaticDir, "ocispec")
+
+ // Make a directory to hold JSON versions of container OCI specs
+ if err := os.MkdirAll(specsDir, 0755); err != nil {
+ // The directory is allowed to exist
+ if !os.IsExist(err) {
+ return nil, errors.Wrapf(err, "error creating runtime OCI specs directory %s",
+ specsDir)
+ }
+ }
+
+ state, err := NewSQLState(dbPath, lockPath, specsDir, runtime)
+ if err != nil {
+ return nil, err
+ }
+ runtime.state = state
+ }
+
// Mark the runtime as valid - ready to be used, cannot be modified
// further
runtime.valid = true
@@ -188,5 +212,10 @@ func (r *Runtime) Shutdown(force bool) error {
r.valid = false
_, err := r.store.Shutdown(force)
- return err
+ if err != nil {
+ return err
+ }
+
+ // TODO: Should always call this even if store.Shutdown failed
+ return r.state.Close()
}