Add support for setting conmon sockets directory in libpod
Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
parent
872c59da8f
commit
3262565d61
3 changed files with 61 additions and 13 deletions
|
@ -41,7 +41,9 @@ type OCIRuntime struct {
|
|||
conmonPath string
|
||||
conmonEnv []string
|
||||
cgroupManager string
|
||||
tmpDir string
|
||||
exitsDir string
|
||||
socketsDir string
|
||||
logSizeMax int64
|
||||
noPivot bool
|
||||
}
|
||||
|
@ -53,21 +55,40 @@ type syncInfo struct {
|
|||
}
|
||||
|
||||
// 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.name = name
|
||||
runtime.path = path
|
||||
runtime.conmonPath = conmonPath
|
||||
runtime.conmonEnv = conmonEnv
|
||||
runtime.cgroupManager = cgroupManager
|
||||
runtime.exitsDir = exitsDir
|
||||
runtime.tmpDir = tmpDir
|
||||
runtime.logSizeMax = logSizeMax
|
||||
runtime.noPivot = noPivotRoot
|
||||
|
||||
runtime.exitsDir = filepath.Join(runtime.tmpDir, "exits")
|
||||
runtime.socketsDir = filepath.Join(runtime.tmpDir, "socket")
|
||||
|
||||
if cgroupManager != CgroupfsCgroupsManager && cgroupManager != SystemdCgroupsManager {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -117,6 +138,7 @@ func (r *OCIRuntime) createContainer(ctr *Container, cgroupParent string) error
|
|||
// The default also likely shouldn't be this
|
||||
args = append(args, "-l", filepath.Join(ctr.config.StaticDir, "ctr.log"))
|
||||
args = append(args, "--exit-dir", r.exitsDir)
|
||||
args = append(args, "--socket-dir-path", r.socketsDir)
|
||||
if ctr.config.Spec.Process.Terminal {
|
||||
args = append(args, "-t")
|
||||
} else if ctr.config.Stdin {
|
||||
|
|
|
@ -150,15 +150,30 @@ func WithCgroupManager(manager string) RuntimeOption {
|
|||
}
|
||||
}
|
||||
|
||||
// WithExitsDir sets the directory that container exit files (containing exit
|
||||
// codes) will be created by conmon
|
||||
func WithExitsDir(dir string) RuntimeOption {
|
||||
// WithStaticDir sets the directory that static runtime files which persist
|
||||
// across reboots will be stored
|
||||
func WithStaticDir(dir string) RuntimeOption {
|
||||
return func(rt *Runtime) error {
|
||||
if rt.valid {
|
||||
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
|
||||
}
|
||||
|
|
|
@ -38,7 +38,8 @@ type RuntimeConfig struct {
|
|||
ConmonPath string
|
||||
ConmonEnvVars []string
|
||||
CgroupManager string
|
||||
ExitsDir string
|
||||
StaticDir string
|
||||
TmpDir string
|
||||
SelinuxEnabled bool
|
||||
PidsLimit int64
|
||||
MaxLogSize int64
|
||||
|
@ -56,7 +57,8 @@ var (
|
|||
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
|
||||
},
|
||||
CgroupManager: "cgroupfs",
|
||||
ExitsDir: "/var/run/libpod/exits",
|
||||
StaticDir: "/var/lib/libpod",
|
||||
TmpDir: "/var/run/libpod",
|
||||
SelinuxEnabled: false,
|
||||
PidsLimit: 1024,
|
||||
MaxLogSize: -1,
|
||||
|
@ -111,19 +113,28 @@ func NewRuntime(options ...RuntimeOption) (*Runtime, error) {
|
|||
// Make an OCI runtime to perform container operations
|
||||
ociRuntime, err := newOCIRuntime("runc", runtime.config.RuntimePath,
|
||||
runtime.config.ConmonPath, runtime.config.ConmonEnvVars,
|
||||
runtime.config.CgroupManager, runtime.config.ExitsDir,
|
||||
runtime.config.CgroupManager, runtime.config.TmpDir,
|
||||
runtime.config.MaxLogSize, runtime.config.NoPivotRoot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
runtime.ociRuntime = ociRuntime
|
||||
|
||||
// Make the directory that will hold container exit files
|
||||
if err := os.MkdirAll(runtime.config.ExitsDir, 0755); err != nil {
|
||||
// Make the static files directory if it does not exist
|
||||
if err := os.MkdirAll(runtime.config.StaticDir, 0755); err != nil {
|
||||
// The directory is allowed to exist
|
||||
if !os.IsExist(err) {
|
||||
return nil, errors.Wrapf(err, "error creating container exit files directory %s",
|
||||
runtime.config.ExitsDir)
|
||||
return nil, errors.Wrapf(err, "error creating runtime static files directory %s",
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue