summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-04-19 16:22:05 -0400
committerGitHub <noreply@github.com>2021-04-19 16:22:05 -0400
commita94360a3f742cac07b006233371058d8b8c2caf3 (patch)
tree3dbbde6b5388f96f1552ca173bf49d0b49fa8e1a /libpod
parentb5e0b292bf4ebf98a1ad45681da5f297d86de44b (diff)
parent4ffaa50d05bcb08d7db242232a128bb3493fcf25 (diff)
downloadpodman-a94360a3f742cac07b006233371058d8b8c2caf3.tar.gz
podman-a94360a3f742cac07b006233371058d8b8c2caf3.tar.bz2
podman-a94360a3f742cac07b006233371058d8b8c2caf3.zip
Merge pull request #10041 from chenk008/add_pidfile_flag
Add flag "--pidfile" for podman create/run
Diffstat (limited to 'libpod')
-rw-r--r--libpod/container_config.go2
-rw-r--r--libpod/container_inspect.go1
-rw-r--r--libpod/define/container_inspect.go1
-rw-r--r--libpod/oci_conmon_linux.go2
-rw-r--r--libpod/options.go11
-rw-r--r--libpod/runtime_ctr.go11
6 files changed, 27 insertions, 1 deletions
diff --git a/libpod/container_config.go b/libpod/container_config.go
index be24b54d6..e6c3be1bd 100644
--- a/libpod/container_config.go
+++ b/libpod/container_config.go
@@ -364,4 +364,6 @@ type ContainerMiscConfig struct {
Timezone string `json:"timezone,omitempty"`
// Umask is the umask inside the container.
Umask string `json:"umask,omitempty"`
+ // PidFile is the file that saves the pid of the container process
+ PidFile string `json:"pid_file,omitempty"`
}
diff --git a/libpod/container_inspect.go b/libpod/container_inspect.go
index e0569e2d4..61cc43314 100644
--- a/libpod/container_inspect.go
+++ b/libpod/container_inspect.go
@@ -128,6 +128,7 @@ func (c *Container) getContainerInspectData(size bool, driverData *define.Driver
StaticDir: config.StaticDir,
OCIRuntime: config.OCIRuntime,
ConmonPidFile: config.ConmonPidFile,
+ PidFile: config.PidFile,
Name: config.Name,
RestartCount: int32(runtimeInfo.RestartCount),
Driver: driverData.Name,
diff --git a/libpod/define/container_inspect.go b/libpod/define/container_inspect.go
index 0f355d20a..1a38f5b0a 100644
--- a/libpod/define/container_inspect.go
+++ b/libpod/define/container_inspect.go
@@ -627,6 +627,7 @@ type InspectContainerData struct {
OCIConfigPath string `json:"OCIConfigPath,omitempty"`
OCIRuntime string `json:"OCIRuntime,omitempty"`
ConmonPidFile string `json:"ConmonPidFile"`
+ PidFile string `json:"PidFile"`
Name string `json:"Name"`
RestartCount int32 `json:"RestartCount"`
Driver string `json:"Driver"`
diff --git a/libpod/oci_conmon_linux.go b/libpod/oci_conmon_linux.go
index 5e8ed12e7..dbe91c232 100644
--- a/libpod/oci_conmon_linux.go
+++ b/libpod/oci_conmon_linux.go
@@ -1025,7 +1025,7 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
}
}
- args := r.sharedConmonArgs(ctr, ctr.ID(), ctr.bundlePath(), filepath.Join(ctr.state.RunDir, "pidfile"), ctr.LogPath(), r.exitsDir, ociLog, ctr.LogDriver(), logTag)
+ args := r.sharedConmonArgs(ctr, ctr.ID(), ctr.bundlePath(), ctr.config.PidFile, ctr.LogPath(), r.exitsDir, ociLog, ctr.LogDriver(), logTag)
if ctr.config.Spec.Process.Terminal {
args = append(args, "-t")
diff --git a/libpod/options.go b/libpod/options.go
index 333a7c4a5..5cd0f7b88 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -1692,6 +1692,17 @@ func WithSecrets(secretNames []string) CtrCreateOption {
}
}
+// WithPidFile adds pidFile to the container
+func WithPidFile(pidFile string) CtrCreateOption {
+ return func(ctr *Container) error {
+ if ctr.valid {
+ return define.ErrCtrFinalized
+ }
+ ctr.config.PidFile = pidFile
+ return nil
+ }
+}
+
// Pod Creation Options
// WithInfraImage sets the infra image for libpod.
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go
index f9b5c5c51..0acf88cbc 100644
--- a/libpod/runtime_ctr.go
+++ b/libpod/runtime_ctr.go
@@ -69,6 +69,13 @@ func (r *Runtime) RestoreContainer(ctx context.Context, rSpec *spec.Spec, config
ctr.config.ConmonPidFile = ""
}
+ // If the path to PidFile starts with the default value (RunRoot), then
+ // the user has not specified '--pidfile' during run or create (probably).
+ // In that case reset PidFile to be set to the default value later.
+ if strings.HasPrefix(ctr.config.PidFile, r.storageConfig.RunRoot) {
+ ctr.config.PidFile = ""
+ }
+
return r.setupContainer(ctx, ctr)
}
@@ -366,6 +373,10 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai
ctr.config.ConmonPidFile = filepath.Join(ctr.state.RunDir, "conmon.pid")
}
+ if ctr.config.PidFile == "" {
+ ctr.config.PidFile = filepath.Join(ctr.state.RunDir, "pidfile")
+ }
+
// Go through named volumes and add them.
// If they don't exist they will be created using basic options.
// Maintain an array of them - we need to lock them later.