github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/runsc/cmd/pause.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 // Pause implements subcommands.Command for the "pause" command. 27 type Pause struct{} 28 29 // Name implements subcommands.Command.Name. 30 func (*Pause) Name() string { 31 return "pause" 32 } 33 34 // Synopsis implements subcommands.Command.Synopsis. 35 func (*Pause) Synopsis() string { 36 return "pause suspends all processes in a container" 37 } 38 39 // Usage implements subcommands.Command.Usage. 40 func (*Pause) Usage() string { 41 return `pause <container id> - pause process in instance of container.` 42 } 43 44 // SetFlags implements subcommands.Command.SetFlags. 45 func (*Pause) SetFlags(f *flag.FlagSet) { 46 } 47 48 // Execute implements subcommands.Command.Execute. 49 func (*Pause) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus { 50 if f.NArg() != 1 { 51 f.Usage() 52 return subcommands.ExitUsageError 53 } 54 55 id := f.Arg(0) 56 conf := args[0].(*config.Config) 57 58 cont, err := container.Load(conf.RootDir, container.FullID{ContainerID: id}, container.LoadOpts{}) 59 if err != nil { 60 Fatalf("loading container: %v", err) 61 } 62 63 if err := cont.Pause(); err != nil { 64 Fatalf("pause failed: %v", err) 65 } 66 67 return subcommands.ExitSuccess 68 }