github.com/containerd/nerdctl@v1.7.7/cmd/nerdctl/compose_pause.go (about) 1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "github.com/containerd/nerdctl/pkg/clientutil" 21 "github.com/containerd/nerdctl/pkg/cmd/compose" 22 "github.com/spf13/cobra" 23 ) 24 25 func newComposePauseCommand() *cobra.Command { 26 var composePauseCommand = &cobra.Command{ 27 Use: "pause [SERVICE...]", 28 Short: "Pause all processes within containers of service(s). They can be unpaused with nerdctl compose unpause", 29 RunE: composePauseAction, 30 SilenceUsage: true, 31 SilenceErrors: true, 32 DisableFlagsInUseLine: true, 33 } 34 return composePauseCommand 35 } 36 37 func composePauseAction(cmd *cobra.Command, args []string) error { 38 globalOptions, err := processRootCmdFlags(cmd) 39 if err != nil { 40 return err 41 } 42 43 client, ctx, cancel, err := clientutil.NewClient(cmd.Context(), globalOptions.Namespace, globalOptions.Address) 44 if err != nil { 45 return err 46 } 47 defer cancel() 48 options, err := getComposeOptions(cmd, globalOptions.DebugFull, globalOptions.Experimental) 49 if err != nil { 50 return err 51 } 52 c, err := compose.New(client, globalOptions, options, cmd.OutOrStdout(), cmd.ErrOrStderr()) 53 if err != nil { 54 return err 55 } 56 57 return c.Pause(ctx, args, cmd.OutOrStdout()) 58 } 59 60 func newComposeUnpauseCommand() *cobra.Command { 61 var composeUnpauseCommand = &cobra.Command{ 62 Use: "unpause [SERVICE...]", 63 Short: "Unpause all processes within containers of service(s).", 64 RunE: composeUnpauseAction, 65 SilenceUsage: true, 66 SilenceErrors: true, 67 DisableFlagsInUseLine: true, 68 } 69 return composeUnpauseCommand 70 } 71 72 func composeUnpauseAction(cmd *cobra.Command, args []string) error { 73 globalOptions, err := processRootCmdFlags(cmd) 74 if err != nil { 75 return err 76 } 77 78 client, ctx, cancel, err := clientutil.NewClient(cmd.Context(), globalOptions.Namespace, globalOptions.Address) 79 if err != nil { 80 return err 81 } 82 defer cancel() 83 84 options, err := getComposeOptions(cmd, globalOptions.DebugFull, globalOptions.Experimental) 85 if err != nil { 86 return err 87 } 88 c, err := compose.New(client, globalOptions, options, cmd.OutOrStdout(), cmd.ErrOrStderr()) 89 if err != nil { 90 return err 91 } 92 93 return c.Unpause(ctx, args, cmd.OutOrStdout()) 94 }