Add support for setting conmon sockets directory in libpod

Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
Matthew Heon 2017-10-23 11:36:10 -04:00
parent 872c59da8f
commit 3262565d61
3 changed files with 61 additions and 13 deletions

View file

@ -41,7 +41,9 @@ type OCIRuntime struct {
conmonPath string conmonPath string
conmonEnv []string conmonEnv []string
cgroupManager string cgroupManager string
tmpDir string
exitsDir string exitsDir string
socketsDir string
logSizeMax int64 logSizeMax int64
noPivot bool noPivot bool
} }
@ -53,21 +55,40 @@ type syncInfo struct {
} }
// Make a new OCI runtime with provided options // Make a new OCI runtime with provided options
func newOCIRuntime(name string, path string, conmonPath string, conmonEnv []string, cgroupManager string, exitsDir string, logSizeMax int64, noPivotRoot bool) (*OCIRuntime, error) { func newOCIRuntime(name string, path string, conmonPath string, conmonEnv []string, cgroupManager string, tmpDir string, logSizeMax int64, noPivotRoot bool) (*OCIRuntime, error) {
runtime := new(OCIRuntime) runtime := new(OCIRuntime)
runtime.name = name runtime.name = name
runtime.path = path runtime.path = path
runtime.conmonPath = conmonPath runtime.conmonPath = conmonPath
runtime.conmonEnv = conmonEnv runtime.conmonEnv = conmonEnv
runtime.cgroupManager = cgroupManager runtime.cgroupManager = cgroupManager
runtime.exitsDir = exitsDir runtime.tmpDir = tmpDir
runtime.logSizeMax = logSizeMax runtime.logSizeMax = logSizeMax
runtime.noPivot = noPivotRoot runtime.noPivot = noPivotRoot
runtime.exitsDir = filepath.Join(runtime.tmpDir, "exits")
runtime.socketsDir = filepath.Join(runtime.tmpDir, "socket")
if cgroupManager != CgroupfsCgroupsManager && cgroupManager != SystemdCgroupsManager { if cgroupManager != CgroupfsCgroupsManager && cgroupManager != SystemdCgroupsManager {
return nil, errors.Wrapf(ErrInvalidArg, "invalid cgroup manager specified: %s", cgroupManager) return nil, errors.Wrapf(ErrInvalidArg, "invalid cgroup manager specified: %s", cgroupManager)
} }
// Create the exit files and attach sockets directories
if err := os.MkdirAll(runtime.exitsDir, 0750); err != nil {
// The directory is allowed to exist
if !os.IsExist(err) {
return nil, errors.Wrapf(err, "error creating OCI runtime exit files directory %s",
runtime.exitsDir)
}
}
if err := os.MkdirAll(runtime.socketsDir, 0750); err != nil {
// The directory is allowed to exist
if !os.IsExist(err) {
return nil, errors.Wrapf(err, "error creating OCI runtime attach sockets directory %s",
runtime.socketsDir)
}
}
return runtime, nil return runtime, nil
} }
@ -117,6 +138,7 @@ func (r *OCIRuntime) createContainer(ctr *Container, cgroupParent string) error
// The default also likely shouldn't be this // The default also likely shouldn't be this
args = append(args, "-l", filepath.Join(ctr.config.StaticDir, "ctr.log")) args = append(args, "-l", filepath.Join(ctr.config.StaticDir, "ctr.log"))
args = append(args, "--exit-dir", r.exitsDir) args = append(args, "--exit-dir", r.exitsDir)
args = append(args, "--socket-dir-path", r.socketsDir)
if ctr.config.Spec.Process.Terminal { if ctr.config.Spec.Process.Terminal {
args = append(args, "-t") args = append(args, "-t")
} else if ctr.config.Stdin { } else if ctr.config.Stdin {

View file

@ -150,15 +150,30 @@ func WithCgroupManager(manager string) RuntimeOption {
} }
} }
// WithExitsDir sets the directory that container exit files (containing exit // WithStaticDir sets the directory that static runtime files which persist
// codes) will be created by conmon // across reboots will be stored
func WithExitsDir(dir string) RuntimeOption { func WithStaticDir(dir string) RuntimeOption {
return func(rt *Runtime) error { return func(rt *Runtime) error {
if rt.valid { if rt.valid {
return ErrRuntimeFinalized return ErrRuntimeFinalized
} }
rt.config.ExitsDir = dir rt.config.StaticDir = dir
return nil
}
}
// WithTmpDir sets the directory that temporary runtime files which are not
// expected to survive across reboots will be stored
// This should be located on a tmpfs mount (/tmp or /var/run for example)
func WithTmpDir(dir string) RuntimeOption {
return func(rt *Runtime) error {
if rt.valid {
return ErrRuntimeFinalized
}
rt.config.TmpDir = dir
return nil return nil
} }

View file

@ -38,7 +38,8 @@ type RuntimeConfig struct {
ConmonPath string ConmonPath string
ConmonEnvVars []string ConmonEnvVars []string
CgroupManager string CgroupManager string
ExitsDir string StaticDir string
TmpDir string
SelinuxEnabled bool SelinuxEnabled bool
PidsLimit int64 PidsLimit int64
MaxLogSize int64 MaxLogSize int64
@ -56,7 +57,8 @@ var (
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
}, },
CgroupManager: "cgroupfs", CgroupManager: "cgroupfs",
ExitsDir: "/var/run/libpod/exits", StaticDir: "/var/lib/libpod",
TmpDir: "/var/run/libpod",
SelinuxEnabled: false, SelinuxEnabled: false,
PidsLimit: 1024, PidsLimit: 1024,
MaxLogSize: -1, MaxLogSize: -1,
@ -111,19 +113,28 @@ func NewRuntime(options ...RuntimeOption) (*Runtime, error) {
// Make an OCI runtime to perform container operations // Make an OCI runtime to perform container operations
ociRuntime, err := newOCIRuntime("runc", runtime.config.RuntimePath, ociRuntime, err := newOCIRuntime("runc", runtime.config.RuntimePath,
runtime.config.ConmonPath, runtime.config.ConmonEnvVars, runtime.config.ConmonPath, runtime.config.ConmonEnvVars,
runtime.config.CgroupManager, runtime.config.ExitsDir, runtime.config.CgroupManager, runtime.config.TmpDir,
runtime.config.MaxLogSize, runtime.config.NoPivotRoot) runtime.config.MaxLogSize, runtime.config.NoPivotRoot)
if err != nil { if err != nil {
return nil, err return nil, err
} }
runtime.ociRuntime = ociRuntime runtime.ociRuntime = ociRuntime
// Make the directory that will hold container exit files // Make the static files directory if it does not exist
if err := os.MkdirAll(runtime.config.ExitsDir, 0755); err != nil { if err := os.MkdirAll(runtime.config.StaticDir, 0755); err != nil {
// The directory is allowed to exist // The directory is allowed to exist
if !os.IsExist(err) { if !os.IsExist(err) {
return nil, errors.Wrapf(err, "error creating container exit files directory %s", return nil, errors.Wrapf(err, "error creating runtime static files directory %s",
runtime.config.ExitsDir) runtime.config.StaticDir)
}
}
// Make the per-boot files directory if it does not exist
if err := os.MkdirAll(runtime.config.TmpDir, 0755); err != nil {
// The directory is allowed to exist
if !os.IsExist(err) {
return nil, errors.Wrapf(err, "error creating runtime temporary files directory %s",
runtime.config.TmpDir)
} }
} }