summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-05-21 16:02:52 +0200
committerGitHub <noreply@github.com>2020-05-21 16:02:52 +0200
commita852afab2f37026fa8a45d115c61cd77fb3e7ef1 (patch)
treef47d5211873d31dadb3b89b69d66397c744b2231 /cmd/podman
parent500ad31d1bd1aee1458b17f05c2dfb7937786e87 (diff)
parent24158d4a2eaa84088ca1ca1e85a0bcbb8399c2ac (diff)
downloadpodman-a852afab2f37026fa8a45d115c61cd77fb3e7ef1.tar.gz
podman-a852afab2f37026fa8a45d115c61cd77fb3e7ef1.tar.bz2
podman-a852afab2f37026fa8a45d115c61cd77fb3e7ef1.zip
Merge pull request #6270 from mheon/detached_exec
Implement detached exec
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/containers/cleanup.go24
-rw-r--r--cmd/podman/containers/exec.go35
2 files changed, 49 insertions, 10 deletions
diff --git a/cmd/podman/containers/cleanup.go b/cmd/podman/containers/cleanup.go
index 2bcd1c1e9..619031208 100644
--- a/cmd/podman/containers/cleanup.go
+++ b/cmd/podman/containers/cleanup.go
@@ -7,6 +7,8 @@ import (
"github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils"
"github.com/containers/libpod/pkg/domain/entities"
+ "github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -43,6 +45,7 @@ func init() {
flags := cleanupCommand.Flags()
flags.BoolVarP(&cleanupOptions.All, "all", "a", false, "Cleans up all containers")
flags.BoolVarP(&cleanupOptions.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
+ flags.StringVar(&cleanupOptions.Exec, "exec", "", "Clean up the given exec session instead of the container")
flags.BoolVar(&cleanupOptions.Remove, "rm", false, "After cleanup, remove the container entirely")
flags.BoolVar(&cleanupOptions.RemoveImage, "rmi", false, "After cleanup, remove the image entirely")
@@ -52,8 +55,26 @@ func cleanup(cmd *cobra.Command, args []string) error {
var (
errs utils.OutputErrors
)
+
+ if cleanupOptions.Exec != "" {
+ switch {
+ case cleanupOptions.All:
+ return errors.Errorf("exec and all options conflict")
+ case len(args) > 1:
+ return errors.Errorf("cannot use exec option when more than one container is given")
+ case cleanupOptions.RemoveImage:
+ return errors.Errorf("exec and rmi options conflict")
+ }
+ }
+
responses, err := registry.ContainerEngine().ContainerCleanup(registry.GetContext(), args, cleanupOptions)
if err != nil {
+ // `podman container cleanup` is almost always run in the
+ // background. Our only way of relaying information to the user
+ // is via syslog.
+ // As such, we need to logrus.Errorf our errors to ensure they
+ // are properly printed if --syslog is set.
+ logrus.Errorf("Error running container cleanup: %v", err)
return err
}
for _, r := range responses {
@@ -62,12 +83,15 @@ func cleanup(cmd *cobra.Command, args []string) error {
continue
}
if r.RmErr != nil {
+ logrus.Errorf("Error removing container: %v", r.RmErr)
errs = append(errs, r.RmErr)
}
if r.RmiErr != nil {
+ logrus.Errorf("Error removing image: %v", r.RmiErr)
errs = append(errs, r.RmiErr)
}
if r.CleanErr != nil {
+ logrus.Errorf("Error cleaning up container: %v", r.CleanErr)
errs = append(errs, r.CleanErr)
}
}
diff --git a/cmd/podman/containers/exec.go b/cmd/podman/containers/exec.go
index 0992b3862..7554d6a93 100644
--- a/cmd/podman/containers/exec.go
+++ b/cmd/podman/containers/exec.go
@@ -2,9 +2,11 @@ package containers
import (
"bufio"
+ "fmt"
"os"
"github.com/containers/libpod/cmd/podman/registry"
+ "github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/pkg/domain/entities"
envLib "github.com/containers/libpod/pkg/env"
"github.com/pkg/errors"
@@ -41,10 +43,12 @@ var (
var (
envInput, envFile []string
execOpts entities.ExecOptions
+ execDetach bool
)
func execFlags(flags *pflag.FlagSet) {
flags.SetInterspersed(false)
+ flags.BoolVarP(&execDetach, "detach", "d", false, "Run the exec session in detached mode (backgrounded)")
flags.StringVar(&execOpts.DetachKeys, "detach-keys", containerConfig.DetachKeys(), "Select the key sequence for detaching a container. Format is a single character [a-Z] or ctrl-<value> where <value> is one of: a-z, @, ^, [, , or _")
flags.StringArrayVarP(&envInput, "env", "e", []string{}, "Set environment variables")
flags.StringSliceVar(&envFile, "env-file", []string{}, "Read in a file of environment variables")
@@ -106,16 +110,27 @@ func exec(cmd *cobra.Command, args []string) error {
}
execOpts.Envs = envLib.Join(execOpts.Envs, cliEnv)
- execOpts.Streams.OutputStream = os.Stdout
- execOpts.Streams.ErrorStream = os.Stderr
- if execOpts.Interactive {
- execOpts.Streams.InputStream = bufio.NewReader(os.Stdin)
- execOpts.Streams.AttachInput = true
+
+ if !execDetach {
+ streams := define.AttachStreams{}
+ streams.OutputStream = os.Stdout
+ streams.ErrorStream = os.Stderr
+ if execOpts.Interactive {
+ streams.InputStream = bufio.NewReader(os.Stdin)
+ streams.AttachInput = true
+ }
+ streams.AttachOutput = true
+ streams.AttachError = true
+
+ exitCode, err := registry.ContainerEngine().ContainerExec(registry.GetContext(), nameOrId, execOpts, streams)
+ registry.SetExitCode(exitCode)
+ return err
}
- execOpts.Streams.AttachOutput = true
- execOpts.Streams.AttachError = true
- exitCode, err := registry.ContainerEngine().ContainerExec(registry.GetContext(), nameOrId, execOpts)
- registry.SetExitCode(exitCode)
- return err
+ id, err := registry.ContainerEngine().ContainerExecDetached(registry.GetContext(), nameOrId, execOpts)
+ if err != nil {
+ return err
+ }
+ fmt.Println(id)
+ return nil
}