github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/runsc/cmd/resume.go (about)

     1  // Copyright 2018 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package cmd
    16  
    17  import (
    18  	"context"
    19  
    20  	"github.com/google/subcommands"
    21  	"github.com/SagerNet/gvisor/runsc/config"
    22  	"github.com/SagerNet/gvisor/runsc/container"
    23  	"github.com/SagerNet/gvisor/runsc/flag"
    24  )
    25  
    26  // Resume implements subcommands.Command for the "resume" command.
    27  type Resume struct{}
    28  
    29  // Name implements subcommands.Command.Name.
    30  func (*Resume) Name() string {
    31  	return "resume"
    32  }
    33  
    34  // Synopsis implements subcommands.Command.Synopsis.
    35  func (*Resume) Synopsis() string {
    36  	return "Resume unpauses a paused container"
    37  }
    38  
    39  // Usage implements subcommands.Command.Usage.
    40  func (*Resume) Usage() string {
    41  	return `resume <container id> - resume a paused container.
    42  `
    43  }
    44  
    45  // SetFlags implements subcommands.Command.SetFlags.
    46  func (r *Resume) SetFlags(f *flag.FlagSet) {
    47  }
    48  
    49  // Execute implements subcommands.Command.Execute.
    50  func (r *Resume) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {
    51  	if f.NArg() != 1 {
    52  		f.Usage()
    53  		return subcommands.ExitUsageError
    54  	}
    55  
    56  	id := f.Arg(0)
    57  	conf := args[0].(*config.Config)
    58  
    59  	cont, err := container.Load(conf.RootDir, container.FullID{ContainerID: id}, container.LoadOpts{})
    60  	if err != nil {
    61  		Fatalf("loading container: %v", err)
    62  	}
    63  
    64  	if err := cont.Resume(); err != nil {
    65  		Fatalf("resume failed: %v", err)
    66  	}
    67  
    68  	return subcommands.ExitSuccess
    69  }