github.com/opencontainers/runc@v1.2.0-rc.1.0.20240520010911-492dc558cdd6/restore.go (about)

     1  package main
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/opencontainers/runc/libcontainer/userns"
     7  	"github.com/sirupsen/logrus"
     8  	"github.com/urfave/cli"
     9  )
    10  
    11  var restoreCommand = cli.Command{
    12  	Name:  "restore",
    13  	Usage: "restore a container from a previous checkpoint",
    14  	ArgsUsage: `<container-id>
    15  
    16  Where "<container-id>" is the name for the instance of the container to be
    17  restored.`,
    18  	Description: `Restores the saved state of the container instance that was previously saved
    19  using the runc checkpoint command.`,
    20  	Flags: []cli.Flag{
    21  		cli.StringFlag{
    22  			Name:  "console-socket",
    23  			Value: "",
    24  			Usage: "path to an AF_UNIX socket which will receive a file descriptor referencing the master end of the console's pseudoterminal",
    25  		},
    26  		cli.StringFlag{
    27  			Name:  "image-path",
    28  			Value: "",
    29  			Usage: "path to criu image files for restoring",
    30  		},
    31  		cli.StringFlag{
    32  			Name:  "work-path",
    33  			Value: "",
    34  			Usage: "path for saving work files and logs",
    35  		},
    36  		cli.BoolFlag{
    37  			Name:  "tcp-established",
    38  			Usage: "allow open tcp connections",
    39  		},
    40  		cli.BoolFlag{
    41  			Name:  "ext-unix-sk",
    42  			Usage: "allow external unix sockets",
    43  		},
    44  		cli.BoolFlag{
    45  			Name:  "shell-job",
    46  			Usage: "allow shell jobs",
    47  		},
    48  		cli.BoolFlag{
    49  			Name:  "file-locks",
    50  			Usage: "handle file locks, for safety",
    51  		},
    52  		cli.StringFlag{
    53  			Name:  "manage-cgroups-mode",
    54  			Value: "",
    55  			Usage: "cgroups mode: soft|full|strict|ignore (default: soft)",
    56  		},
    57  		cli.StringFlag{
    58  			Name:  "bundle, b",
    59  			Value: "",
    60  			Usage: "path to the root of the bundle directory",
    61  		},
    62  		cli.BoolFlag{
    63  			Name:  "detach,d",
    64  			Usage: "detach from the container's process",
    65  		},
    66  		cli.StringFlag{
    67  			Name:  "pid-file",
    68  			Value: "",
    69  			Usage: "specify the file to write the process id to",
    70  		},
    71  		cli.BoolFlag{
    72  			Name:  "no-subreaper",
    73  			Usage: "disable the use of the subreaper used to reap reparented processes",
    74  		},
    75  		cli.BoolFlag{
    76  			Name:  "no-pivot",
    77  			Usage: "do not use pivot root to jail process inside rootfs.  This should be used whenever the rootfs is on top of a ramdisk",
    78  		},
    79  		cli.StringSliceFlag{
    80  			Name:  "empty-ns",
    81  			Usage: "create a namespace, but don't restore its properties",
    82  		},
    83  		cli.BoolFlag{
    84  			Name:  "auto-dedup",
    85  			Usage: "enable auto deduplication of memory images",
    86  		},
    87  		cli.BoolFlag{
    88  			Name:  "lazy-pages",
    89  			Usage: "use userfaultfd to lazily restore memory pages",
    90  		},
    91  		cli.StringFlag{
    92  			Name:  "lsm-profile",
    93  			Value: "",
    94  			Usage: "Specify an LSM profile to be used during restore in the form of TYPE:NAME.",
    95  		},
    96  		cli.StringFlag{
    97  			Name:  "lsm-mount-context",
    98  			Value: "",
    99  			Usage: "Specify an LSM mount context to be used during restore.",
   100  		},
   101  	},
   102  	Action: func(context *cli.Context) error {
   103  		if err := checkArgs(context, 1, exactArgs); err != nil {
   104  			return err
   105  		}
   106  		// XXX: Currently this is untested with rootless containers.
   107  		if os.Geteuid() != 0 || userns.RunningInUserNS() {
   108  			logrus.Warn("runc checkpoint is untested with rootless containers")
   109  		}
   110  
   111  		options, err := criuOptions(context)
   112  		if err != nil {
   113  			return err
   114  		}
   115  		status, err := startContainer(context, CT_ACT_RESTORE, options)
   116  		if err != nil {
   117  			return err
   118  		}
   119  		// exit with the container's exit status so any external supervisor is
   120  		// notified of the exit with the correct exit status.
   121  		os.Exit(status)
   122  		return nil
   123  	},
   124  }