mirror of
https://github.com/containers/podman.git
synced 2025-05-17 15:18:43 +08:00
Migrate can move containers to a new runtime
This is a horrible hack to work around issues with Fedora 31, but other distros might need it to, so we'll move it upstream. I do not recommend this functionality for general use, and the manpages and other documentation will reflect this. But for some upgrade cases, it will be the only thing that allows for a working system. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
This commit is contained in:
@ -5,14 +5,15 @@ package libpod
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/containers/libpod/pkg/util"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"github.com/containers/libpod/libpod/define"
|
||||
"github.com/containers/libpod/pkg/rootless"
|
||||
"github.com/containers/libpod/pkg/util"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -63,11 +64,34 @@ func (r *Runtime) migrate(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Did the user request a new runtime?
|
||||
runtimeChangeRequested := r.migrateRuntime != ""
|
||||
requestedRuntime, runtimeExists := r.ociRuntimes[r.migrateRuntime]
|
||||
if !runtimeExists && runtimeChangeRequested {
|
||||
return errors.Wrapf(define.ErrInvalidArg, "change to runtime %q requested but no such runtime is defined", r.migrateRuntime)
|
||||
}
|
||||
|
||||
for _, ctr := range allCtrs {
|
||||
needsWrite := false
|
||||
|
||||
// Reset pause process location
|
||||
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")
|
||||
needsWrite = true
|
||||
}
|
||||
|
||||
// Reset runtime
|
||||
if runtimeChangeRequested {
|
||||
logrus.Infof("Resetting container %s runtime to runtime %s", ctr.ID(), r.migrateRuntime)
|
||||
ctr.config.OCIRuntime = r.migrateRuntime
|
||||
ctr.ociRuntime = requestedRuntime
|
||||
|
||||
needsWrite = true
|
||||
}
|
||||
|
||||
if needsWrite {
|
||||
if err := r.state.RewriteContainerConfig(ctr, ctr.config); err != nil {
|
||||
return errors.Wrapf(err, "error rewriting config for container %s", ctr.ID())
|
||||
}
|
||||
|
Reference in New Issue
Block a user