github.com/containerd/containerd@v22.0.0-20200918172823-438c87b8e050+incompatible/cmd/ctr/commands/tasks/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 tasks
    18  
    19  import (
    20  	"github.com/containerd/containerd/cmd/ctr/commands"
    21  	"github.com/urfave/cli"
    22  )
    23  
    24  var pauseCommand = cli.Command{
    25  	Name:      "pause",
    26  	Usage:     "pause an existing container",
    27  	ArgsUsage: "CONTAINER",
    28  	Action: func(context *cli.Context) error {
    29  		client, ctx, cancel, err := commands.NewClient(context)
    30  		if err != nil {
    31  			return err
    32  		}
    33  		defer cancel()
    34  		container, err := client.LoadContainer(ctx, context.Args().First())
    35  		if err != nil {
    36  			return err
    37  		}
    38  		task, err := container.Task(ctx, nil)
    39  		if err != nil {
    40  			return err
    41  		}
    42  		return task.Pause(ctx)
    43  	},
    44  }