aboutsummaryrefslogtreecommitdiff
path: root/libpod/runtime.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-03-01 15:33:04 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-03-06 01:21:09 +0000
commit32be712cd32bbfb7babb27e5405db08967a5af71 (patch)
treeadc99361ae8fae7dd2c46bebe9d81e06f54ef1e5 /libpod/runtime.go
parentbd8557da858b9743f99aab42c762197cd291fe04 (diff)
downloadpodman-32be712cd32bbfb7babb27e5405db08967a5af71.tar.gz
podman-32be712cd32bbfb7babb27e5405db08967a5af71.tar.bz2
podman-32be712cd32bbfb7babb27e5405db08967a5af71.zip
Change standard config path and add override config
The standard config has moved to /usr/share/containers/ per discussion. An override configuration file is allowed at the previous /etc/containers/ location. This override will be used in place of the normal config if both are present, and exists to override distro packaged configs without modifying the standard config. Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #430 Approved by: rhatdan
Diffstat (limited to 'libpod/runtime.go')
-rw-r--r--libpod/runtime.go38
1 files changed, 23 insertions, 15 deletions
diff --git a/libpod/runtime.go b/libpod/runtime.go
index 3570290c0..a2331e38e 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -44,7 +44,11 @@ const (
// If it is not present, the builtin default config is used instead
// This path can be overridden when the runtime is created by using
// NewRuntimeFromConfig() instead of NewRuntime()
- ConfigPath = "/etc/containers/libpod.conf"
+ ConfigPath = "/usr/share/containers/libpod.conf"
+ // OverrideConfigPath is the path to an override for the default libpod
+ // configuration file. If OverrideConfigPath exists, it will be used in
+ // place of the configuration file pointed to by ConfigPath.
+ OverrideConfigPath = "/etc/containers/libpod.conf"
)
// A RuntimeOption is a functional option which alters the Runtime created by
@@ -163,20 +167,24 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
// Copy the default configuration
deepcopier.Copy(defaultRuntimeConfig).To(runtime.config)
- // Now overwrite it with the given configuration file, if it exists
- // Do not fail on error, instead just use the builtin defaults
- if _, err := os.Stat(ConfigPath); err == nil {
- // Read the contents of the config file
- contents, err := ioutil.ReadFile(ConfigPath)
- if err == nil {
- // Only proceed if we successfully read the file
- _, err := toml.Decode(string(contents), runtime.config)
- if err != nil {
- // We may have just ruined our RuntimeConfig
- // Make a new one to be safe
- runtime.config = new(RuntimeConfig)
- deepcopier.Copy(defaultRuntimeConfig).To(runtime.config)
- }
+ configPath := ConfigPath
+ foundConfig := true
+ if _, err := os.Stat(OverrideConfigPath); err == nil {
+ // Use the override configuration path
+ configPath = OverrideConfigPath
+ } else if _, err := os.Stat(ConfigPath); err != nil {
+ // Both stat checks failed, no config found
+ foundConfig = false
+ }
+
+ // If we have a valid configuration file, load it in
+ if foundConfig {
+ contents, err := ioutil.ReadFile(configPath)
+ if err != nil {
+ return nil, errors.Wrapf(err, "error reading configuration file %s", configPath)
+ }
+ if _, err := toml.Decode(string(contents), runtime.config); err != nil {
+ return nil, errors.Wrapf(err, "error decoding configuration file %s", configPath)
}
}