From 8fbe06b8cbd8e3bc425d83130d562eb0c19f309b Mon Sep 17 00:00:00 2001 From: "wuhua.ck" Date: Thu, 15 Apr 2021 22:36:50 +0800 Subject: add flag "--pidfile" for podman create/run Signed-off-by: chenkang --- cmd/podman/common/create.go | 6 ++++++ cmd/podman/common/create_opts.go | 1 + cmd/podman/common/specgen.go | 1 + cmd/podman/containers/create.go | 4 ++++ cmd/podman/containers/run.go | 2 ++ docs/source/markdown/podman-create.1.md | 7 +++++++ docs/source/markdown/podman-run.1.md | 6 ++++++ libpod/container_config.go | 2 ++ libpod/oci_conmon_linux.go | 7 ++++++- libpod/options.go | 11 +++++++++++ pkg/specgen/generate/container_create.go | 3 +++ pkg/specgen/specgen.go | 4 ++++ 12 files changed, 53 insertions(+), 1 deletion(-) 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-`, where `` 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 -- cgit v1.2.3-54-g00ecf From 4fb5fee4120165d43ee6b98f7258cda741d41d45 Mon Sep 17 00:00:00 2001 From: chenkang Date: Fri, 16 Apr 2021 15:12:57 +0800 Subject: add ut Signed-off-by: chenkang --- test/e2e/run_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go index cefe00655..ac459f6ab 100644 --- a/test/e2e/run_test.go +++ b/test/e2e/run_test.go @@ -1613,4 +1613,12 @@ WORKDIR /madethis`, BB) Expect(running.ExitCode()).To(Equal(0)) Expect(len(running.OutputToStringArray())).To(Equal(2)) }) + + It("podman run with pidfile", func() { + session := podmanTest.Podman([]string{"run", "--pidfile", tempdir + "pidfile", ALPINE, "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + err := os.Remove(tempdir + "pidfile") + Expect(err).To(BeNil()) + }) }) -- cgit v1.2.3-54-g00ecf From e16200ac9f0e8fde836a14cc6951203e8986122a Mon Sep 17 00:00:00 2001 From: chenkang Date: Fri, 16 Apr 2021 15:52:03 +0800 Subject: add flag autocomplete Signed-off-by: chenkang --- cmd/podman/common/create.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/podman/common/create.go b/cmd/podman/common/create.go index e574f228e..da391d30d 100644 --- a/cmd/podman/common/create.go +++ b/cmd/podman/common/create.go @@ -822,6 +822,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *ContainerCLIOpts) { &cf.PidFile, pidFileFlagName, "", "Write the container process ID to the file") + _ = cmd.RegisterFlagCompletionFunc(pidFileFlagName, completion.AutocompleteDefault) _ = createFlags.MarkHidden("signature-policy") if registry.IsRemote() { -- cgit v1.2.3-54-g00ecf From f331c9445f0be468a47a43e290845f7b637535d5 Mon Sep 17 00:00:00 2001 From: chenkang Date: Fri, 16 Apr 2021 23:09:17 +0800 Subject: hide conmon-pidfile flag on remote mode Signed-off-by: chenkang --- cmd/podman/containers/create.go | 1 + cmd/podman/containers/run.go | 1 + 2 files changed, 2 insertions(+) diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go index 5d2f3aad6..507e9c221 100644 --- a/cmd/podman/containers/create.go +++ b/cmd/podman/containers/create.go @@ -65,6 +65,7 @@ func createFlags(cmd *cobra.Command) { flags.SetNormalizeFunc(utils.AliasFlags) if registry.IsRemote() { + _ = flags.MarkHidden("conmon-pidfile") _ = flags.MarkHidden("pidfile") } } diff --git a/cmd/podman/containers/run.go b/cmd/podman/containers/run.go index fa3310fad..8e27977c0 100644 --- a/cmd/podman/containers/run.go +++ b/cmd/podman/containers/run.go @@ -79,6 +79,7 @@ func runFlags(cmd *cobra.Command) { if registry.IsRemote() { _ = flags.MarkHidden("preserve-fds") + _ = flags.MarkHidden("conmon-pidfile") _ = flags.MarkHidden("pidfile") } } -- cgit v1.2.3-54-g00ecf From 80c1dd0651ac7f70f09c1a5259a17f5cef59ab13 Mon Sep 17 00:00:00 2001 From: chenkang Date: Fri, 16 Apr 2021 23:45:10 +0800 Subject: Modify according to comments Signed-off-by: chenkang --- docs/source/markdown/podman-create.1.md | 11 +++++++++-- docs/source/markdown/podman-run.1.md | 12 ++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/source/markdown/podman-create.1.md b/docs/source/markdown/podman-create.1.md index 08b1db9ba..1ac5a3951 100644 --- a/docs/source/markdown/podman-create.1.md +++ b/docs/source/markdown/podman-create.1.md @@ -149,6 +149,7 @@ Write the container ID to the file #### **\-\-conmon-pidfile**=*path* Write the pid of the `conmon` process to a file. `conmon` runs in a separate process than Podman, so this is necessary when using systemd to restart Podman containers. +(This option is not available with the remote Podman client) #### **\-\-cpu-period**=*limit* @@ -1226,9 +1227,15 @@ can override the working directory by using the **-w** option. #### **\-\-pidfile**=*path* -Write the pid of the container process to a file. +When the pidfile location is specified, the container process' PID will be written to the pidfile. (This option is not available with the remote Podman client) +After the container is started, the location for the pidfile can be discovered with the following `podman inspect` command: -The default pidfile is RunDir/pidfile. + $ podman inspect --format '{{ .Config.CreateCommand }}' $CID + podman run --pidfile $pidfilepath image + +If the pidfile option is not specified, the container process' PID will be written to +/run/containers/storage/${storage-driver}-containers/$CID/userdata/pidfile. +The default pidfile location is not listed in the `podman inspect` output. ## EXAMPLES diff --git a/docs/source/markdown/podman-run.1.md b/docs/source/markdown/podman-run.1.md index 1fa6ede06..5285d9608 100644 --- a/docs/source/markdown/podman-run.1.md +++ b/docs/source/markdown/podman-run.1.md @@ -167,6 +167,7 @@ Write the container ID to *file*. #### **\-\-conmon-pidfile**=*file* Write the pid of the **conmon** process to a file. As **conmon** runs in a separate process than Podman, this is necessary when using systemd to restart Podman containers. +(This option is not available with the remote Podman client) #### **\-\-cpu-period**=*limit* @@ -1307,9 +1308,16 @@ can override the working directory by using the **-w** option. #### **\-\-pidfile**=*path* -Write the pid of the container process to a file. +When the pidfile location is specified, the container process' PID will be written to the pidfile. (This option is not available with the remote Podman client) +After the container is started, the location for the pidfile can be discovered with the following `podman inspect` command: + + $ podman inspect --format '{{ .Config.CreateCommand }}' $CID + podman run --pidfile $pidfilepath image + +If the pidfile option is not specified, the container process' PID will be written to +/run/containers/storage/${storage-driver}-containers/$CID/userdata/pidfile. +The default pidfile location is not listed in the `podman inspect` output. -The default pidfile is RunDir/pidfile. ## Exit Status -- cgit v1.2.3-54-g00ecf From c9f347e9a8c013348d236bc205b3eca13d3f29ef Mon Sep 17 00:00:00 2001 From: chenkang Date: Sat, 17 Apr 2021 20:32:19 +0800 Subject: skip pidfile it on remote Signed-off-by: chenkang --- test/e2e/run_test.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go index ac459f6ab..93505d742 100644 --- a/test/e2e/run_test.go +++ b/test/e2e/run_test.go @@ -1615,10 +1615,18 @@ WORKDIR /madethis`, BB) }) It("podman run with pidfile", func() { - session := podmanTest.Podman([]string{"run", "--pidfile", tempdir + "pidfile", ALPINE, "ls"}) + SkipIfRemote("pidfile not handled by remote") + pidfile := tempdir + "pidfile" + session := podmanTest.Podman([]string{"run", "--pidfile", pidfile, ALPINE, "ls"}) session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) - err := os.Remove(tempdir + "pidfile") + readFirstLine := func(path string) string { + content, err := ioutil.ReadFile(path) + Expect(err).To(BeNil()) + return strings.Split(string(content), "\n")[0] + } + containerPID := readFirstLine(pidfile) + _, err = strconv.Atoi(containerPID) // Make sure it's a proper integer Expect(err).To(BeNil()) }) }) -- cgit v1.2.3-54-g00ecf From f3f7ae5cddada6a1faa4bef21c586efb83c70c19 Mon Sep 17 00:00:00 2001 From: chenkang Date: Sat, 17 Apr 2021 20:42:21 +0800 Subject: add pidfile it for container start Signed-off-by: chenkang --- test/e2e/start_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/e2e/start_test.go b/test/e2e/start_test.go index f527b67f6..be724ab35 100644 --- a/test/e2e/start_test.go +++ b/test/e2e/start_test.go @@ -1,7 +1,10 @@ package integration import ( + "io/ioutil" "os" + "strconv" + "strings" . "github.com/containers/podman/v3/test/utils" . "github.com/onsi/ginkgo" @@ -206,4 +209,23 @@ var _ = Describe("Podman start", func() { session.WaitWithDefaultTimeout() Expect(session).Should(Exit(125)) }) + + It("podman start container with special pidfile", func() { + pidfile := tempdir + "pidfile" + session := podmanTest.Podman([]string{"create", "--pidfile", pidfile, ALPINE, "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + cid := session.OutputToString() + + session = podmanTest.Podman([]string{"start", cid}) + Expect(session.ExitCode()).To(Equal(0)) + readFirstLine := func(path string) string { + content, err := ioutil.ReadFile(path) + Expect(err).To(BeNil()) + return strings.Split(string(content), "\n")[0] + } + containerPID := readFirstLine(pidfile) + _, err = strconv.Atoi(containerPID) // Make sure it's a proper integer + Expect(err).To(BeNil()) + }) }) -- cgit v1.2.3-54-g00ecf From b963a5eb4a62688d3fc5c11815bc626055201187 Mon Sep 17 00:00:00 2001 From: chenkang Date: Sat, 17 Apr 2021 20:55:57 +0800 Subject: add pidfile in inspection Signed-off-by: chenkang --- libpod/container_inspect.go | 1 + libpod/define/container_inspect.go | 1 + 2 files changed, 2 insertions(+) diff --git a/libpod/container_inspect.go b/libpod/container_inspect.go index e0569e2d4..57968039f 100644 --- a/libpod/container_inspect.go +++ b/libpod/container_inspect.go @@ -141,6 +141,7 @@ func (c *Container) getContainerInspectData(size bool, driverData *define.Driver Mounts: inspectMounts, Dependencies: c.Dependencies(), IsInfra: c.IsInfra(), + PidFile: config.PidFile, } if c.state.ConfigPath != "" { diff --git a/libpod/define/container_inspect.go b/libpod/define/container_inspect.go index 0f355d20a..126ce85a6 100644 --- a/libpod/define/container_inspect.go +++ b/libpod/define/container_inspect.go @@ -647,6 +647,7 @@ type InspectContainerData struct { IsInfra bool `json:"IsInfra"` Config *InspectContainerConfig `json:"Config"` HostConfig *InspectContainerHostConfig `json:"HostConfig"` + PidFile string `json:"PidFile"` } // InspectExecSession contains information about a given exec session. -- cgit v1.2.3-54-g00ecf From 728b73d7c4186f4f0f9431d84ec2c5883f38ff20 Mon Sep 17 00:00:00 2001 From: chenkang Date: Sat, 17 Apr 2021 21:15:08 +0800 Subject: set pidfile default value int containerconfig Signed-off-by: chenkang --- libpod/oci_conmon_linux.go | 7 +------ libpod/runtime_ctr.go | 4 ++++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/libpod/oci_conmon_linux.go b/libpod/oci_conmon_linux.go index c5735d114..dbe91c232 100644 --- a/libpod/oci_conmon_linux.go +++ b/libpod/oci_conmon_linux.go @@ -1025,12 +1025,7 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co } } - 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) + 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/runtime_ctr.go b/libpod/runtime_ctr.go index f9b5c5c51..6290479a8 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -366,6 +366,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. -- cgit v1.2.3-54-g00ecf From 022bf589c8ee23783721038f7b9e536ac489add7 Mon Sep 17 00:00:00 2001 From: chenkang Date: Sat, 17 Apr 2021 21:25:11 +0800 Subject: improve document Signed-off-by: chenkang --- docs/source/markdown/podman-create.1.md | 10 ++++------ docs/source/markdown/podman-run.1.md | 11 ++++------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/docs/source/markdown/podman-create.1.md b/docs/source/markdown/podman-create.1.md index 1ac5a3951..db9ff937b 100644 --- a/docs/source/markdown/podman-create.1.md +++ b/docs/source/markdown/podman-create.1.md @@ -1228,14 +1228,12 @@ can override the working directory by using the **-w** option. #### **\-\-pidfile**=*path* When the pidfile location is specified, the container process' PID will be written to the pidfile. (This option is not available with the remote Podman client) -After the container is started, the location for the pidfile can be discovered with the following `podman inspect` command: +If the pidfile option is not specified, the container process' PID will be written to /run/containers/storage/${storage-driver}-containers/$CID/userdata/pidfile. - $ podman inspect --format '{{ .Config.CreateCommand }}' $CID - podman run --pidfile $pidfilepath image +After the container is started, the location for the pidfile can be discovered with the following `podman inspect` command: -If the pidfile option is not specified, the container process' PID will be written to -/run/containers/storage/${storage-driver}-containers/$CID/userdata/pidfile. -The default pidfile location is not listed in the `podman inspect` output. + $ podman inspect --format '{{ .PidFile }}' $CID + /run/containers/storage/${storage-driver}-containers/$CID/userdata/pidfile ## EXAMPLES diff --git a/docs/source/markdown/podman-run.1.md b/docs/source/markdown/podman-run.1.md index 5285d9608..f84a5913c 100644 --- a/docs/source/markdown/podman-run.1.md +++ b/docs/source/markdown/podman-run.1.md @@ -1309,15 +1309,12 @@ can override the working directory by using the **-w** option. #### **\-\-pidfile**=*path* When the pidfile location is specified, the container process' PID will be written to the pidfile. (This option is not available with the remote Podman client) -After the container is started, the location for the pidfile can be discovered with the following `podman inspect` command: - - $ podman inspect --format '{{ .Config.CreateCommand }}' $CID - podman run --pidfile $pidfilepath image +If the pidfile option is not specified, the container process' PID will be written to /run/containers/storage/${storage-driver}-containers/$CID/userdata/pidfile. -If the pidfile option is not specified, the container process' PID will be written to -/run/containers/storage/${storage-driver}-containers/$CID/userdata/pidfile. -The default pidfile location is not listed in the `podman inspect` output. +After the container is started, the location for the pidfile can be discovered with the following `podman inspect` command: + $ podman inspect --format '{{ .PidFile }}' $CID + /run/containers/storage/${storage-driver}-containers/$CID/userdata/pidfile ## Exit Status -- cgit v1.2.3-54-g00ecf From 4ce7aa6ee8aac132c4447d8a1be0fbce31d53bdc Mon Sep 17 00:00:00 2001 From: chenkang Date: Sat, 17 Apr 2021 22:30:43 +0800 Subject: skip pidfile test on remote Signed-off-by: chenkang --- test/e2e/start_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e/start_test.go b/test/e2e/start_test.go index be724ab35..d5d12fc71 100644 --- a/test/e2e/start_test.go +++ b/test/e2e/start_test.go @@ -211,6 +211,7 @@ var _ = Describe("Podman start", func() { }) It("podman start container with special pidfile", func() { + SkipIfRemote("pidfile not handled by remote") pidfile := tempdir + "pidfile" session := podmanTest.Podman([]string{"create", "--pidfile", pidfile, ALPINE, "ls"}) session.WaitWithDefaultTimeout() -- cgit v1.2.3-54-g00ecf From a1002beb78e3a63c0704f5cd8f6ff6556e60bb2f Mon Sep 17 00:00:00 2001 From: chenkang Date: Sat, 17 Apr 2021 23:35:27 +0800 Subject: fix start it Signed-off-by: chenkang --- libpod/container_inspect.go | 2 +- libpod/define/container_inspect.go | 2 +- test/e2e/start_test.go | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libpod/container_inspect.go b/libpod/container_inspect.go index 57968039f..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, @@ -141,7 +142,6 @@ func (c *Container) getContainerInspectData(size bool, driverData *define.Driver Mounts: inspectMounts, Dependencies: c.Dependencies(), IsInfra: c.IsInfra(), - PidFile: config.PidFile, } if c.state.ConfigPath != "" { diff --git a/libpod/define/container_inspect.go b/libpod/define/container_inspect.go index 126ce85a6..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"` @@ -647,7 +648,6 @@ type InspectContainerData struct { IsInfra bool `json:"IsInfra"` Config *InspectContainerConfig `json:"Config"` HostConfig *InspectContainerHostConfig `json:"HostConfig"` - PidFile string `json:"PidFile"` } // InspectExecSession contains information about a given exec session. diff --git a/test/e2e/start_test.go b/test/e2e/start_test.go index d5d12fc71..cb2db0810 100644 --- a/test/e2e/start_test.go +++ b/test/e2e/start_test.go @@ -219,6 +219,7 @@ var _ = Describe("Podman start", func() { cid := session.OutputToString() session = podmanTest.Podman([]string{"start", cid}) + session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) readFirstLine := func(path string) string { content, err := ioutil.ReadFile(path) -- cgit v1.2.3-54-g00ecf From a35e16c23456a8fba8d2f627ac64f647aa6f0722 Mon Sep 17 00:00:00 2001 From: chenkang Date: Sun, 18 Apr 2021 00:02:50 +0800 Subject: support pidfile on container restore Signed-off-by: chenkang --- libpod/runtime_ctr.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 6290479a8..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) } -- cgit v1.2.3-54-g00ecf From 4ffaa50d05bcb08d7db242232a128bb3493fcf25 Mon Sep 17 00:00:00 2001 From: chenkang Date: Sun, 18 Apr 2021 21:29:12 +0800 Subject: add it for inspect pidfile Signed-off-by: chenkang --- test/e2e/inspect_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/e2e/inspect_test.go b/test/e2e/inspect_test.go index 772ebed05..ba018b5ad 100644 --- a/test/e2e/inspect_test.go +++ b/test/e2e/inspect_test.go @@ -508,4 +508,14 @@ var _ = Describe("Podman inspect", func() { Expect(data[0].HostConfig.CapDrop[1]).To(Equal("CAP_MKNOD")) Expect(data[0].HostConfig.CapDrop[2]).To(Equal("CAP_NET_RAW")) }) + + It("podman inspect container with GO format for PidFile", func() { + SkipIfRemote("pidfile not handled by remote") + session, ec, _ := podmanTest.RunLsContainer("test1") + Expect(ec).To(Equal(0)) + + session = podmanTest.Podman([]string{"inspect", "--format", "{{.PidFile}}", "test1"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + }) }) -- cgit v1.2.3-54-g00ecf