summaryrefslogtreecommitdiff
path: root/cmd/podman/system/migrate.go
blob: 28c23d88f695c061f68c27b5fed5fd543d0cac29 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// +build !remote

package system

import (
	"fmt"
	"os"

	"github.com/containers/libpod/cmd/podman/registry"
	"github.com/containers/libpod/cmd/podman/validate"
	"github.com/containers/libpod/pkg/domain/entities"
	"github.com/containers/libpod/pkg/domain/infra"
	"github.com/spf13/cobra"
)

var (
	migrateDescription = `
        podman system migrate

        Migrate existing containers to a new version of Podman.
`

	migrateCommand = &cobra.Command{
		Use:   "migrate",
		Args:  validate.NoArgs,
		Short: "Migrate containers",
		Long:  migrateDescription,
		Run:   migrate,
	}
)

var (
	migrateOptions entities.SystemMigrateOptions
)

func init() {
	registry.Commands = append(registry.Commands, registry.CliCommand{
		Mode:    []entities.EngineMode{entities.ABIMode},
		Command: migrateCommand,
		Parent:  systemCmd,
	})

	flags := migrateCommand.Flags()
	flags.StringVar(&migrateOptions.NewRuntime, "new-runtime", "", "Specify a new runtime for all containers")
}

func migrate(cmd *cobra.Command, args []string) {
	// Shutdown all running engines, `renumber` will hijack repository
	registry.ContainerEngine().Shutdown(registry.Context())
	registry.ImageEngine().Shutdown(registry.Context())

	engine, err := infra.NewSystemEngine(entities.MigrateMode, registry.PodmanConfig())
	if err != nil {
		fmt.Println(err)
		os.Exit(125)
	}
	defer engine.Shutdown(registry.Context())

	err = engine.Migrate(registry.Context(), cmd.Flags(), registry.PodmanConfig(), migrateOptions)
	if err != nil {
		fmt.Println(err)
		os.Exit(125)
	}
	os.Exit(0)
}