summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwuhua.ck <wuhua.ck@alibaba-inc.com>2021-04-15 22:36:50 +0800
committerchenkang <kongchen28@gmail.com>2021-04-16 13:43:14 +0800
commit8fbe06b8cbd8e3bc425d83130d562eb0c19f309b (patch)
treedb52b4259b92ad6fb30bbe3ff07d01eb7ce208ef
parent373f15f617db6731c58776c1766a4cf2c74b22b9 (diff)
downloadpodman-8fbe06b8cbd8e3bc425d83130d562eb0c19f309b.tar.gz
podman-8fbe06b8cbd8e3bc425d83130d562eb0c19f309b.tar.bz2
podman-8fbe06b8cbd8e3bc425d83130d562eb0c19f309b.zip
add flag "--pidfile" for podman create/run
Signed-off-by: chenkang <kongchen28@gmail.com>
-rw-r--r--cmd/podman/common/create.go6
-rw-r--r--cmd/podman/common/create_opts.go1
-rw-r--r--cmd/podman/common/specgen.go1
-rw-r--r--cmd/podman/containers/create.go4
-rw-r--r--cmd/podman/containers/run.go2
-rw-r--r--docs/source/markdown/podman-create.1.md7
-rw-r--r--docs/source/markdown/podman-run.1.md6
-rw-r--r--libpod/container_config.go2
-rw-r--r--libpod/oci_conmon_linux.go7
-rw-r--r--libpod/options.go11
-rw-r--r--pkg/specgen/generate/container_create.go3
-rw-r--r--pkg/specgen/specgen.go4
12 files changed, 53 insertions, 1 deletions
diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go
index 220a30a10..e574f228e 100644
--- a/cmd/podman/common/create.go
+++ b/cmd/podman/common/create.go
@@ -817,6 +817,12 @@ func DefineCreateFlags(cmd *cobra.Command, cf *ContainerCLIOpts) {
)
_ = cmd.RegisterFlagCompletionFunc(cgroupConfFlagName, completion.AutocompleteNone)
+ pidFileFlagName := "pidfile"
+ createFlags.StringVar(
+ &cf.PidFile,
+ pidFileFlagName, "",
+ "Write the container process ID to the file")
+
_ = createFlags.MarkHidden("signature-policy")
if registry.IsRemote() {
_ = createFlags.MarkHidden("env-host")
diff --git a/cmd/podman/common/create_opts.go b/cmd/podman/common/create_opts.go
index e14918fe1..040dc6570 100644
--- a/cmd/podman/common/create_opts.go
+++ b/cmd/podman/common/create_opts.go
@@ -122,6 +122,7 @@ type ContainerCLIOpts struct {
VolumesFrom []string
Workdir string
SeccompPolicy string
+ PidFile string
Net *entities.NetOptions
diff --git a/cmd/podman/common/specgen.go b/cmd/podman/common/specgen.go
index 363a8f5f9..310a07a00 100644
--- a/cmd/podman/common/specgen.go
+++ b/cmd/podman/common/specgen.go
@@ -644,6 +644,7 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
s.Timezone = c.Timezone
s.Umask = c.Umask
s.Secrets = c.Secrets
+ s.PidFile = c.PidFile
return nil
}
diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go
index 2da9aaf5e..5d2f3aad6 100644
--- a/cmd/podman/containers/create.go
+++ b/cmd/podman/containers/create.go
@@ -63,6 +63,10 @@ func createFlags(cmd *cobra.Command) {
common.DefineNetFlags(cmd)
flags.SetNormalizeFunc(utils.AliasFlags)
+
+ if registry.IsRemote() {
+ _ = flags.MarkHidden("pidfile")
+ }
}
func init() {
diff --git a/cmd/podman/containers/run.go b/cmd/podman/containers/run.go
index 1a9fa2f0f..fa3310fad 100644
--- a/cmd/podman/containers/run.go
+++ b/cmd/podman/containers/run.go
@@ -76,8 +76,10 @@ func runFlags(cmd *cobra.Command) {
detachKeysFlagName := "detach-keys"
flags.StringVar(&runOpts.DetachKeys, detachKeysFlagName, containerConfig.DetachKeys(), "Override the key sequence for detaching a container. Format is a single character `[a-Z]` or a comma separated sequence of `ctrl-<value>`, where `<value>` is one of: `a-cf`, `@`, `^`, `[`, `\\`, `]`, `^` or `_`")
_ = cmd.RegisterFlagCompletionFunc(detachKeysFlagName, common.AutocompleteDetachKeys)
+
if registry.IsRemote() {
_ = flags.MarkHidden("preserve-fds")
+ _ = flags.MarkHidden("pidfile")
}
}
diff --git a/docs/source/markdown/podman-create.1.md b/docs/source/markdown/podman-create.1.md
index ae6dfe03b..08b1db9ba 100644
--- a/docs/source/markdown/podman-create.1.md
+++ b/docs/source/markdown/podman-create.1.md
@@ -1224,6 +1224,13 @@ The default working directory for running binaries within a container is the roo
The image developer can set a different default with the WORKDIR instruction. The operator
can override the working directory by using the **-w** option.
+#### **\-\-pidfile**=*path*
+
+Write the pid of the container process to a file.
+
+The default pidfile is RunDir/pidfile.
+
+
## EXAMPLES
### Create a container using a local image
diff --git a/docs/source/markdown/podman-run.1.md b/docs/source/markdown/podman-run.1.md
index 40b271828..1fa6ede06 100644
--- a/docs/source/markdown/podman-run.1.md
+++ b/docs/source/markdown/podman-run.1.md
@@ -1305,6 +1305,12 @@ The default working directory for running binaries within a container is the roo
The image developer can set a different default with the WORKDIR instruction. The operator
can override the working directory by using the **-w** option.
+#### **\-\-pidfile**=*path*
+
+Write the pid of the container process to a file.
+
+The default pidfile is RunDir/pidfile.
+
## Exit Status
The exit code from **podman run** gives information about why the container
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/oci_conmon_linux.go b/libpod/oci_conmon_linux.go
index 5e8ed12e7..c5735d114 100644
--- a/libpod/oci_conmon_linux.go
+++ b/libpod/oci_conmon_linux.go
@@ -1025,7 +1025,12 @@ 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)
+ pidfile := ctr.config.PidFile
+ if pidfile == "" {
+ pidfile = filepath.Join(ctr.state.RunDir, "pidfile")
+ }
+
+ args := r.sharedConmonArgs(ctr, ctr.ID(), ctr.bundlePath(), 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/pkg/specgen/generate/container_create.go b/pkg/specgen/generate/container_create.go
index ef9975021..13d4b4926 100644
--- a/pkg/specgen/generate/container_create.go
+++ b/pkg/specgen/generate/container_create.go
@@ -375,6 +375,9 @@ func createContainerOptions(ctx context.Context, rt *libpod.Runtime, s *specgen.
}
options = append(options, libpod.WithDependencyCtrs(deps))
}
+ if s.PidFile != "" {
+ options = append(options, libpod.WithPidFile(s.PidFile))
+ }
return options, nil
}
diff --git a/pkg/specgen/specgen.go b/pkg/specgen/specgen.go
index 28111f96d..e3d4b1436 100644
--- a/pkg/specgen/specgen.go
+++ b/pkg/specgen/specgen.go
@@ -171,6 +171,10 @@ type ContainerBasicConfig struct {
// container. Dependencies can be specified by name or full/partial ID.
// Optional.
DependencyContainers []string `json:"dependencyContainers,omitempty"`
+ // PidFile is the file that saves container process id.
+ // set tags as `json:"-"` for not supported remote
+ // Optional.
+ PidFile string `json:"-"`
}
// ContainerStorageConfig contains information on the storage configuration of a