forked from containers/podman
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
system: add new subcommand "migrate"
it is useful to migrate existing containers to a new version of podman. Currently, it is needed to migrate rootless containers that were created with podman <= 1.2 to a newer version which requires all containers to be running in the same user namespace. Closes: containers#2935 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
- Loading branch information
Showing
10 changed files
with
173 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(&c.PodmanCommand) | ||
if err != nil { | ||
return errors.Wrapf(err, "error migrating containers") | ||
} | ||
if err := r.Shutdown(false); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
% podman-system-migrate(1) podman | ||
|
||
## NAME | ||
podman\-system\-migrate - Migrate container to the latest version of podman | ||
|
||
## SYNOPSIS | ||
** podman system migrate** | ||
|
||
## DESCRIPTION | ||
** podman system migrate** migrates containers to the latest podman version. | ||
|
||
**podman system migrate** takes care of migrating existing containers to the latest version of podman if any change is necessary. | ||
|
||
## SYNOPSIS | ||
**podman system migrate** | ||
|
||
## SEE ALSO | ||
`podman(1)`, `libpod.conf(5)` | ||
|
||
# HISTORY | ||
April 2019, Originally compiled by Giuseppe Scrivano (gscrivan at redhat dot com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package libpod | ||
|
||
import ( | ||
"context" | ||
"path/filepath" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
func (r *Runtime) migrate() error { | ||
runningContainers, err := r.GetRunningContainers() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
allCtrs, err := r.state.AllContainers() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
logrus.Infof("stopping all containers") | ||
for _, ctr := range runningContainers { | ||
logrus.Infof("stopping %s", ctr.ID()) | ||
if err := ctr.Stop(); err != nil { | ||
return errors.Wrapf(err, "cannot stop container %s", ctr.ID()) | ||
} | ||
} | ||
|
||
for _, ctr := range allCtrs { | ||
oldLocation := filepath.Join(ctr.state.RunDir, "conmon.pid") | ||
if ctr.config.ConmonPidFile == oldLocation { | ||
logrus.Infof("changing conmon PID file for %s", ctr.ID()) | ||
ctr.config.ConmonPidFile = filepath.Join(ctr.config.StaticDir, "conmon.pid") | ||
if err := r.state.RewriteContainerConfig(ctr, ctr.config); err != nil { | ||
return errors.Wrapf(err, "error rewriting config for container %s", ctr.ID()) | ||
} | ||
} | ||
} | ||
|
||
for _, ctr := range runningContainers { | ||
if err := ctr.Start(context.Background(), true); err != nil { | ||
logrus.Errorf("error restarting container %s", ctr.ID()) | ||
} | ||
} | ||
|
||
return nil | ||
} |