github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/pause.go (about)

     1  // +build linux
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"os"
     8  
     9  	"github.com/urfave/cli"
    10  )
    11  
    12  var pauseCommand = cli.Command{
    13  	Name:  "pause",
    14  	Usage: "pause suspends all processes inside the container",
    15  	ArgsUsage: `<container-id> [container-id...]
    16  
    17  Where "<container-id>" is the name for the instance of the container to be
    18  paused. `,
    19  	Description: `The pause command suspends all processes in the instance of the container.
    20  
    21  Use runc list to identiy instances of containers and their current status.`,
    22  	Action: func(context *cli.Context) error {
    23  		hasError := false
    24  		if !context.Args().Present() {
    25  			return fmt.Errorf("runc: \"pause\" requires a minimum of 1 argument")
    26  		}
    27  
    28  		factory, err := loadFactory(context)
    29  		if err != nil {
    30  			return err
    31  		}
    32  
    33  		for _, id := range context.Args() {
    34  			container, err := factory.Load(id)
    35  			if err != nil {
    36  				fmt.Fprintf(os.Stderr, "container %s does not exist\n", id)
    37  				hasError = true
    38  				continue
    39  			}
    40  			if err := container.Pause(); err != nil {
    41  				fmt.Fprintf(os.Stderr, "pause container %s : %s\n", id, err)
    42  				hasError = true
    43  			}
    44  		}
    45  
    46  		if hasError {
    47  			return fmt.Errorf("one or more of container pause failed")
    48  		}
    49  		return nil
    50  	},
    51  }
    52  
    53  var resumeCommand = cli.Command{
    54  	Name:  "resume",
    55  	Usage: "resumes all processes that have been previously paused",
    56  	ArgsUsage: `<container-id> [container-id...]
    57  
    58  Where "<container-id>" is the name for the instance of the container to be
    59  resumed.`,
    60  	Description: `The resume command resumes all processes in the instance of the container.
    61  
    62  Use runc list to identiy instances of containers and their current status.`,
    63  	Action: func(context *cli.Context) error {
    64  		hasError := false
    65  		if !context.Args().Present() {
    66  			return fmt.Errorf("runc: \"resume\" requires a minimum of 1 argument")
    67  		}
    68  
    69  		factory, err := loadFactory(context)
    70  		if err != nil {
    71  			return err
    72  		}
    73  
    74  		for _, id := range context.Args() {
    75  			container, err := factory.Load(id)
    76  			if err != nil {
    77  				fmt.Fprintf(os.Stderr, "container %s does not exist\n", id)
    78  				hasError = true
    79  				continue
    80  			}
    81  			if err := container.Resume(); err != nil {
    82  				fmt.Fprintf(os.Stderr, "resume container %s : %s\n", id, err)
    83  				hasError = true
    84  			}
    85  		}
    86  
    87  		if hasError {
    88  			return fmt.Errorf("one or more of container resume failed")
    89  		}
    90  		return nil
    91  	},
    92  }