github.com/MerlinKodo/gvisor@v0.0.0-20231110090155-957f62ecf90e/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/MerlinKodo/gvisor/runsc/cmd/util"
    21  	"github.com/MerlinKodo/gvisor/runsc/config"
    22  	"github.com/MerlinKodo/gvisor/runsc/container"
    23  	"github.com/MerlinKodo/gvisor/runsc/flag"
    24  	"github.com/google/subcommands"
    25  )
    26  
    27  // Resume implements subcommands.Command for the "resume" command.
    28  type Resume struct{}
    29  
    30  // Name implements subcommands.Command.Name.
    31  func (*Resume) Name() string {
    32  	return "resume"
    33  }
    34  
    35  // Synopsis implements subcommands.Command.Synopsis.
    36  func (*Resume) Synopsis() string {
    37  	return "Resume unpauses a paused container"
    38  }
    39  
    40  // Usage implements subcommands.Command.Usage.
    41  func (*Resume) Usage() string {
    42  	return `resume <container id> - resume a paused container.
    43  `
    44  }
    45  
    46  // SetFlags implements subcommands.Command.SetFlags.
    47  func (r *Resume) SetFlags(*flag.FlagSet) {
    48  }
    49  
    50  // Execute implements subcommands.Command.Execute.
    51  func (r *Resume) Execute(_ context.Context, f *flag.FlagSet, args ...any) subcommands.ExitStatus {
    52  	if f.NArg() != 1 {
    53  		f.Usage()
    54  		return subcommands.ExitUsageError
    55  	}
    56  
    57  	id := f.Arg(0)
    58  	conf := args[0].(*config.Config)
    59  
    60  	cont, err := container.Load(conf.RootDir, container.FullID{ContainerID: id}, container.LoadOpts{})
    61  	if err != nil {
    62  		util.Fatalf("loading container: %v", err)
    63  	}
    64  
    65  	if err := cont.Resume(); err != nil {
    66  		util.Fatalf("resume failed: %v", err)
    67  	}
    68  
    69  	return subcommands.ExitSuccess
    70  }