aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/system_migrate.go
blob: 4a0afcfad3543bc312d61f4a2b0877ea189362b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main

import (
	"github.com/containers/libpod/cmd/podman/cliconfig"
	"github.com/containers/libpod/cmd/podman/libpodruntime"
	"github.com/pkg/errors"
	"github.com/spf13/cobra"
)

var (
	migrateCommand     cliconfig.SystemMigrateValues
	migrateDescription = `
        podman system migrate

        Migrate existing containers to a new version of Podman.
`

	_migrateCommand = &cobra.Command{
		Use:   "migrate",
		Args:  noSubArgs,
		Short: "Migrate containers",
		Long:  migrateDescription,
		RunE: func(cmd *cobra.Command, args []string) error {
			migrateCommand.InputArgs = args
			migrateCommand.GlobalFlags = MainGlobalOpts
			return migrateCmd(&migrateCommand)
		},
	}
)

func init() {
	migrateCommand.Command = _migrateCommand
	migrateCommand.SetHelpTemplate(HelpTemplate())
	migrateCommand.SetUsageTemplate(UsageTemplate())
}

func migrateCmd(c *cliconfig.SystemMigrateValues) error {
	// We need to pass one extra option to NewRuntime.
	// This will inform the OCI runtime to start a migrate.
	// That's controlled by the last argument to GetRuntime.
	r, err := libpodruntime.GetRuntimeMigrate(getContext(), &c.PodmanCommand)
	if err != nil {
		return errors.Wrapf(err, "error migrating containers")
	}
	if err := r.Shutdown(false); err != nil {
		return err
	}

	return nil
}