github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/cmd/podman/pod_unpause.go (about) 1 package main 2 3 import ( 4 "fmt" 5 6 "github.com/containers/libpod/cmd/podman/cliconfig" 7 "github.com/containers/libpod/pkg/adapter" 8 "github.com/pkg/errors" 9 "github.com/sirupsen/logrus" 10 "github.com/spf13/cobra" 11 ) 12 13 var ( 14 podUnpauseCommand cliconfig.PodUnpauseValues 15 podUnpauseDescription = `The podman unpause command will unpause all "paused" containers assigned to the pod. 16 17 The pod name or ID can be used.` 18 _podUnpauseCommand = &cobra.Command{ 19 Use: "unpause [flags] POD [POD...]", 20 Short: "Unpause one or more pods", 21 Long: podUnpauseDescription, 22 RunE: func(cmd *cobra.Command, args []string) error { 23 podUnpauseCommand.InputArgs = args 24 podUnpauseCommand.GlobalFlags = MainGlobalOpts 25 podUnpauseCommand.Remote = remoteclient 26 return podUnpauseCmd(&podUnpauseCommand) 27 }, 28 Args: func(cmd *cobra.Command, args []string) error { 29 return checkAllLatestAndCIDFile(cmd, args, false, false) 30 }, 31 Example: `podman pod unpause podID1 podID2 32 podman pod unpause --all 33 podman pod unpause --latest`, 34 } 35 ) 36 37 func init() { 38 podUnpauseCommand.Command = _podUnpauseCommand 39 podUnpauseCommand.SetHelpTemplate(HelpTemplate()) 40 podUnpauseCommand.SetUsageTemplate(UsageTemplate()) 41 flags := podUnpauseCommand.Flags() 42 flags.BoolVarP(&podUnpauseCommand.All, "all", "a", false, "Unpause all running pods") 43 flags.BoolVarP(&podUnpauseCommand.Latest, "latest", "l", false, "Unpause the latest pod podman is aware of") 44 markFlagHiddenForRemoteClient("latest", flags) 45 } 46 47 func podUnpauseCmd(c *cliconfig.PodUnpauseValues) error { 48 var lastError error 49 runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand) 50 if err != nil { 51 return errors.Wrapf(err, "error creating libpod runtime") 52 } 53 defer runtime.DeferredShutdown(false) 54 55 unpauseIDs, conErrors, unpauseErrors := runtime.UnpausePods(c) 56 57 for _, p := range unpauseIDs { 58 fmt.Println(p) 59 } 60 if len(conErrors) > 0 { 61 for ctr, err := range conErrors { 62 if lastError != nil { 63 logrus.Errorf("%q", lastError) 64 } 65 lastError = errors.Wrapf(err, "unable to unpause container %s", ctr) 66 } 67 } 68 if len(unpauseErrors) > 0 { 69 lastError = unpauseErrors[len(unpauseErrors)-1] 70 // Remove the last error from the error slice 71 unpauseErrors = unpauseErrors[:len(unpauseErrors)-1] 72 } 73 for _, err := range unpauseErrors { 74 logrus.Errorf("%q", err) 75 } 76 return lastError 77 }