summaryrefslogtreecommitdiff
path: root/libpod/runtime.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/runtime.go')
-rw-r--r--libpod/runtime.go77
1 files changed, 51 insertions, 26 deletions
diff --git a/libpod/runtime.go b/libpod/runtime.go
index c9471247c..5ff8b30f6 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -86,7 +86,7 @@ type Runtime struct {
imageContext *types.SystemContext
ociRuntime *OCIRuntime
netPlugin ocicni.CNIPlugin
- ociRuntimePath string
+ ociRuntimePath OCIRuntimePath
conmonPath string
valid bool
lock sync.RWMutex
@@ -96,6 +96,14 @@ type Runtime struct {
configuredFrom *runtimeConfiguredFrom
}
+// OCIRuntimePath contains information about an OCI runtime.
+type OCIRuntimePath struct {
+ // Name of the runtime to refer to by the --runtime flag
+ Name string `toml:"name"`
+ // Paths to check for this executable
+ Paths []string `toml:"paths"`
+}
+
// RuntimeConfig contains configuration options used to set up the runtime
type RuntimeConfig struct {
// StorageConfig is the configuration used by containers/storage
@@ -118,10 +126,10 @@ type RuntimeConfig struct {
// cause conflicts in containers/storage
// As such this is not exposed via the config file
StateType RuntimeStateStore `toml:"-"`
- // RuntimePath is the path to OCI runtime binary for launching
- // containers
- // The first path pointing to a valid file will be used
- RuntimePath []string `toml:"runtime_path"`
+ // OCIRuntime is the OCI runtime to use.
+ OCIRuntime string `toml:"runtime"`
+ // OCIRuntimes are the set of configured OCI runtimes (default is runc)
+ OCIRuntimes map[string][]string `toml:"runtimes"`
// ConmonPath is the path to the Conmon binary used for managing
// containers
// The first path pointing to a valid file will be used
@@ -213,14 +221,17 @@ var (
StorageConfig: storage.StoreOptions{},
ImageDefaultTransport: DefaultTransport,
StateType: BoltDBStateStore,
- RuntimePath: []string{
- "/usr/bin/runc",
- "/usr/sbin/runc",
- "/usr/local/bin/runc",
- "/usr/local/sbin/runc",
- "/sbin/runc",
- "/bin/runc",
- "/usr/lib/cri-o-runc/sbin/runc",
+ OCIRuntime: "runc",
+ OCIRuntimes: map[string][]string{
+ "runc": {
+ "/usr/bin/runc",
+ "/usr/sbin/runc",
+ "/usr/local/bin/runc",
+ "/usr/local/sbin/runc",
+ "/sbin/runc",
+ "/bin/runc",
+ "/usr/lib/cri-o-runc/sbin/runc",
+ },
},
ConmonPath: []string{
"/usr/libexec/podman/conmon",
@@ -414,8 +425,9 @@ func NewRuntimeFromConfig(configPath string, options ...RuntimeOption) (runtime
runtime.config = new(RuntimeConfig)
runtime.configuredFrom = new(runtimeConfiguredFrom)
- // Set two fields not in the TOML config
+ // Set three fields not in the TOML config
runtime.config.StateType = defaultRuntimeConfig.StateType
+ runtime.config.OCIRuntime = defaultRuntimeConfig.OCIRuntime
runtime.config.StorageConfig = storage.StoreOptions{}
// Check to see if the given configuration file exists
@@ -453,22 +465,35 @@ func NewRuntimeFromConfig(configPath string, options ...RuntimeOption) (runtime
func makeRuntime(runtime *Runtime) (err error) {
// Find a working OCI runtime binary
foundRuntime := false
- for _, path := range runtime.config.RuntimePath {
- stat, err := os.Stat(path)
- if err != nil {
- continue
- }
- if stat.IsDir() {
- continue
- }
+ // If runtime is an absolute path, then use it as it is.
+ if runtime.config.OCIRuntime[0] == '/' {
foundRuntime = true
- runtime.ociRuntimePath = path
- break
+ runtime.ociRuntimePath = OCIRuntimePath{Name: filepath.Base(runtime.config.OCIRuntime), Paths: []string{runtime.config.OCIRuntime}}
+ } else {
+ // If not, look it up in the configuration.
+ paths := runtime.config.OCIRuntimes[runtime.config.OCIRuntime]
+ if paths != nil {
+ for _, path := range paths {
+ stat, err := os.Stat(path)
+ if err != nil {
+ if os.IsNotExist(err) {
+ continue
+ }
+ return errors.Wrapf(err, "cannot stat %s", path)
+ }
+ if !stat.Mode().IsRegular() {
+ continue
+ }
+ foundRuntime = true
+ runtime.ociRuntimePath = OCIRuntimePath{Name: runtime.config.OCIRuntime, Paths: []string{path}}
+ break
+ }
+ }
}
if !foundRuntime {
return errors.Wrapf(ErrInvalidArg,
"could not find a working binary (configured options: %v)",
- runtime.config.RuntimePath)
+ runtime.config.OCIRuntimes)
}
// Find a working conmon binary
@@ -619,7 +644,7 @@ func makeRuntime(runtime *Runtime) (err error) {
}
// Make an OCI runtime to perform container operations
- ociRuntime, err := newOCIRuntime("runc", runtime.ociRuntimePath,
+ ociRuntime, err := newOCIRuntime(runtime.ociRuntimePath,
runtime.conmonPath, runtime.config.ConmonEnvVars,
runtime.config.CgroupManager, runtime.config.TmpDir,
runtime.config.MaxLogSize, runtime.config.NoPivotRoot,