summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-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
}