summaryrefslogtreecommitdiffhomepage
path: root/runsc/cmd
diff options
context:
space:
mode:
authorBrielle Broder <bbroder@google.com>2018-06-21 09:57:33 -0700
committerShentubot <shentubot@google.com>2018-06-21 09:58:24 -0700
commit7d6149063a0bb6e563885a8f199756e7af5e69cf (patch)
tree44378246b5a4535184658b854066baa5b0bac6d0 /runsc/cmd
parent81d13fbd4d2f14b61e89faa0c9888be568f97168 (diff)
Restore implementation added to runsc.
Restore creates a new container and uses the given image-path to load a saved image of a previous container. Restore command is plumbed through container and sandbox. This command does not work yet - more to come. PiperOrigin-RevId: 201541229 Change-Id: I864a14c799ce3717d99bcdaaebc764281863d06f
Diffstat (limited to 'runsc/cmd')
-rw-r--r--runsc/cmd/create.go2
-rw-r--r--runsc/cmd/restore.go55
2 files changed, 53 insertions, 4 deletions
diff --git a/runsc/cmd/create.go b/runsc/cmd/create.go
index 94a889077..5a887c73c 100644
--- a/runsc/cmd/create.go
+++ b/runsc/cmd/create.go
@@ -87,7 +87,7 @@ func (c *Create) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}
// Create the container. A new sandbox will be created for the
// container unless the metadata specifies that it should be run in an
// existing container.
- if _, err := container.Create(id, spec, conf, bundleDir, c.consoleSocket, c.pidFile); err != nil {
+ if _, err := container.Create(id, spec, conf, bundleDir, c.consoleSocket, c.pidFile, ""); err != nil {
Fatalf("error creating container: %v", err)
}
return subcommands.ExitSuccess
diff --git a/runsc/cmd/restore.go b/runsc/cmd/restore.go
index a535197a4..0589a36bf 100644
--- a/runsc/cmd/restore.go
+++ b/runsc/cmd/restore.go
@@ -15,13 +15,23 @@
package cmd
import (
+ "syscall"
+
"context"
"flag"
"github.com/google/subcommands"
+ "gvisor.googlesource.com/gvisor/runsc/boot"
+ "gvisor.googlesource.com/gvisor/runsc/container"
+ "gvisor.googlesource.com/gvisor/runsc/specutils"
)
// Restore implements subcommands.Command for the "restore" command.
type Restore struct {
+ // Restore flags are a super-set of those for Create.
+ Create
+
+ // imagePath is the path to the saved container image
+ imagePath string
}
// Name implements subcommands.Command.Name.
@@ -36,16 +46,55 @@ func (*Restore) Synopsis() string {
// Usage implements subcommands.Command.Usage.
func (*Restore) Usage() string {
- return `restore [flags] <container id> - restore last saved state of container.
+ return `restore [flags] <container id> - restore saved state of container.
`
}
// SetFlags implements subcommands.Command.SetFlags.
func (r *Restore) SetFlags(f *flag.FlagSet) {
+ r.Create.SetFlags(f)
+ f.StringVar(&r.imagePath, "image-path", "", "path to saved container image")
}
// Execute implements subcommands.Command.Execute.
func (r *Restore) Execute(_ context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {
- Fatalf("restore not implemented")
- return subcommands.ExitFailure
+ if f.NArg() != 1 {
+ f.Usage()
+ return subcommands.ExitUsageError
+ }
+
+ id := f.Arg(0)
+ conf := args[0].(*boot.Config)
+ waitStatus := args[1].(*syscall.WaitStatus)
+
+ bundleDir := r.bundleDir
+ if bundleDir == "" {
+ bundleDir = getwdOrDie()
+ }
+ spec, err := specutils.ReadSpec(bundleDir)
+ if err != nil {
+ Fatalf("error reading spec: %v", err)
+ }
+ specutils.LogSpec(spec)
+
+ if r.imagePath == "" {
+ Fatalf("image-path flag must be provided")
+ }
+
+ cont, err := container.Create(id, spec, conf, bundleDir, r.consoleSocket, r.pidFile, r.imagePath)
+ if err != nil {
+ Fatalf("error restoring container: %v", err)
+ }
+
+ if err := cont.Start(conf); err != nil {
+ Fatalf("error starting container: %v", err)
+ }
+
+ ws, err := cont.Wait()
+ if err != nil {
+ Fatalf("error running container: %v", err)
+ }
+ *waitStatus = ws
+
+ return subcommands.ExitSuccess
}