mirror of
https://github.com/containers/podman.git
synced 2025-07-04 01:48:28 +08:00
add flag "--pidfile" for podman create/run
Signed-off-by: chenkang <kongchen28@gmail.com>
This commit is contained in:
@ -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")
|
||||
|
@ -122,6 +122,7 @@ type ContainerCLIOpts struct {
|
||||
VolumesFrom []string
|
||||
Workdir string
|
||||
SeccompPolicy string
|
||||
PidFile string
|
||||
|
||||
Net *entities.NetOptions
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -63,6 +63,10 @@ func createFlags(cmd *cobra.Command) {
|
||||
common.DefineNetFlags(cmd)
|
||||
|
||||
flags.SetNormalizeFunc(utils.AliasFlags)
|
||||
|
||||
if registry.IsRemote() {
|
||||
_ = flags.MarkHidden("pidfile")
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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"`
|
||||
}
|
||||
|
@ -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")
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user