summaryrefslogtreecommitdiff
path: root/cmd/podman/pods/stop.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/pods/stop.go')
-rw-r--r--cmd/podman/pods/stop.go35
1 files changed, 24 insertions, 11 deletions
diff --git a/cmd/podman/pods/stop.go b/cmd/podman/pods/stop.go
index daf05d640..628e8a536 100644
--- a/cmd/podman/pods/stop.go
+++ b/cmd/podman/pods/stop.go
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
+ "github.com/containers/libpod/cmd/podman/common"
"github.com/containers/libpod/cmd/podman/parse"
"github.com/containers/libpod/cmd/podman/registry"
"github.com/containers/libpod/cmd/podman/utils"
@@ -11,7 +12,18 @@ import (
"github.com/spf13/cobra"
)
+// allows for splitting API and CLI-only options
+type podStopOptionsWrapper struct {
+ entities.PodStopOptions
+
+ PodIDFiles []string
+ TimeoutCLI uint
+}
+
var (
+ stopOptions = podStopOptionsWrapper{
+ PodStopOptions: entities.PodStopOptions{Timeout: -1},
+ }
podStopDescription = `The pod name or ID can be used.
This command will stop all running containers in each of the specified pods.`
@@ -22,7 +34,7 @@ var (
Long: podStopDescription,
RunE: stop,
Args: func(cmd *cobra.Command, args []string) error {
- return parse.CheckAllLatestAndCIDFile(cmd, args, false, false)
+ return parse.CheckAllLatestAndPodIDFile(cmd, args, false, true)
},
Example: `podman pod stop mywebserverpod
podman pod stop --latest
@@ -30,13 +42,6 @@ var (
}
)
-var (
- stopOptions = entities.PodStopOptions{
- Timeout: -1,
- }
- timeout uint
-)
-
func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Mode: []entities.EngineMode{entities.ABIMode, entities.TunnelMode},
@@ -47,7 +52,8 @@ func init() {
flags.BoolVarP(&stopOptions.All, "all", "a", false, "Stop all running pods")
flags.BoolVarP(&stopOptions.Ignore, "ignore", "i", false, "Ignore errors when a specified pod is missing")
flags.BoolVarP(&stopOptions.Latest, "latest", "l", false, "Stop the latest pod podman is aware of")
- flags.UintVarP(&timeout, "time", "t", containerConfig.Engine.StopTimeout, "Seconds to wait for pod stop before killing the container")
+ flags.UintVarP(&stopOptions.TimeoutCLI, "time", "t", containerConfig.Engine.StopTimeout, "Seconds to wait for pod stop before killing the container")
+ flags.StringArrayVarP(&stopOptions.PodIDFiles, "pod-id-file", "", nil, "Read the pod ID from the file")
if registry.IsRemote() {
_ = flags.MarkHidden("latest")
_ = flags.MarkHidden("ignore")
@@ -60,9 +66,16 @@ func stop(cmd *cobra.Command, args []string) error {
errs utils.OutputErrors
)
if cmd.Flag("time").Changed {
- stopOptions.Timeout = int(timeout)
+ stopOptions.Timeout = int(stopOptions.TimeoutCLI)
+ }
+
+ ids, err := common.ReadPodIDFiles(stopOptions.PodIDFiles)
+ if err != nil {
+ return err
}
- responses, err := registry.ContainerEngine().PodStop(context.Background(), args, stopOptions)
+ args = append(args, ids...)
+
+ responses, err := registry.ContainerEngine().PodStop(context.Background(), args, stopOptions.PodStopOptions)
if err != nil {
return err
}