github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/cmd/podman/unpause.go (about) 1 package main 2 3 import ( 4 "github.com/containers/libpod/cmd/podman/cliconfig" 5 "github.com/containers/libpod/libpod/define" 6 "github.com/containers/libpod/pkg/adapter" 7 "github.com/containers/libpod/pkg/rootless" 8 "github.com/pkg/errors" 9 "github.com/spf13/cobra" 10 ) 11 12 var ( 13 unpauseCommand cliconfig.UnpauseValues 14 15 unpauseDescription = `Unpauses one or more previously paused containers. The container name or ID can be used.` 16 _unpauseCommand = &cobra.Command{ 17 Use: "unpause [flags] CONTAINER [CONTAINER...]", 18 Short: "Unpause the processes in one or more containers", 19 Long: unpauseDescription, 20 RunE: func(cmd *cobra.Command, args []string) error { 21 unpauseCommand.InputArgs = args 22 unpauseCommand.GlobalFlags = MainGlobalOpts 23 unpauseCommand.Remote = remoteclient 24 return unpauseCmd(&unpauseCommand) 25 }, 26 Example: `podman unpause ctrID 27 podman unpause --all`, 28 } 29 ) 30 31 func init() { 32 unpauseCommand.Command = _unpauseCommand 33 unpauseCommand.SetHelpTemplate(HelpTemplate()) 34 unpauseCommand.SetUsageTemplate(UsageTemplate()) 35 flags := unpauseCommand.Flags() 36 flags.BoolVarP(&unpauseCommand.All, "all", "a", false, "Unpause all paused containers") 37 } 38 39 func unpauseCmd(c *cliconfig.UnpauseValues) error { 40 if rootless.IsRootless() && !remoteclient { 41 return errors.New("unpause is not supported for rootless containers") 42 } 43 44 runtime, err := adapter.GetRuntime(getContext(), &c.PodmanCommand) 45 if err != nil { 46 return errors.Wrapf(err, "could not get runtime") 47 } 48 defer runtime.DeferredShutdown(false) 49 50 args := c.InputArgs 51 if len(args) < 1 && !c.All { 52 return errors.Errorf("you must provide at least one container name or id") 53 } 54 ok, failures, err := runtime.UnpauseContainers(getContext(), c) 55 if err != nil { 56 if errors.Cause(err) == define.ErrNoSuchCtr { 57 if len(c.InputArgs) > 1 { 58 exitCode = define.ExecErrorCodeGeneric 59 } else { 60 exitCode = 1 61 } 62 } 63 return err 64 } 65 if len(failures) > 0 { 66 exitCode = define.ExecErrorCodeGeneric 67 } 68 return printCmdResults(ok, failures) 69 }