12
"github.com/containers/podman/v5/libpod/define"
13
"github.com/containers/podman/v5/pkg/rootless"
14
"github.com/containers/podman/v5/pkg/util"
15
"github.com/sirupsen/logrus"
18
func (r *Runtime) stopPauseProcess() error {
19
if rootless.IsRootless() {
20
pausePidPath, err := util.GetRootlessPauseProcessPidPath()
22
return fmt.Errorf("could not get pause process pid file path: %w", err)
24
data, err := os.ReadFile(pausePidPath)
26
if os.IsNotExist(err) {
29
return fmt.Errorf("cannot read pause process pid file: %w", err)
31
pausePid, err := strconv.Atoi(string(data))
33
return fmt.Errorf("cannot parse pause pid file %s: %w", pausePidPath, err)
35
if err := os.Remove(pausePidPath); err != nil {
36
return fmt.Errorf("cannot delete pause pid file %s: %w", pausePidPath, err)
38
if err := syscall.Kill(pausePid, syscall.SIGKILL); err != nil {
45
// Migrate stops the rootless pause process and performs any necessary database
46
// migrations that are required. It can also migrate all containers to a new OCI
47
// runtime, if requested.
48
func (r *Runtime) Migrate(newRuntime string) error {
49
// Acquire the alive lock and hold it.
50
// Ensures that we don't let other Podman commands run while we are
51
// rewriting things in the DB.
52
aliveLock, err := r.getRuntimeAliveLock()
54
return fmt.Errorf("retrieving alive lock: %w", err)
57
defer aliveLock.Unlock()
60
return define.ErrRuntimeStopped
63
runningContainers, err := r.GetRunningContainers()
68
allCtrs, err := r.state.AllContainers(false)
73
logrus.Infof("Stopping all containers")
74
for _, ctr := range runningContainers {
75
fmt.Printf("stopped %s\n", ctr.ID())
76
if err := ctr.Stop(); err != nil {
77
return fmt.Errorf("cannot stop container %s: %w", ctr.ID(), err)
81
// Did the user request a new runtime?
82
runtimeChangeRequested := newRuntime != ""
83
var requestedRuntime OCIRuntime
84
if runtimeChangeRequested {
85
runtime, exists := r.ociRuntimes[newRuntime]
87
return fmt.Errorf("change to runtime %q requested but no such runtime is defined: %w", newRuntime, define.ErrInvalidArg)
89
requestedRuntime = runtime
92
for _, ctr := range allCtrs {
95
// Reset pause process location
96
oldLocation := filepath.Join(ctr.state.RunDir, "conmon.pid")
97
if ctr.config.ConmonPidFile == oldLocation {
98
logrus.Infof("Changing conmon PID file for %s", ctr.ID())
99
ctr.config.ConmonPidFile = filepath.Join(ctr.config.StaticDir, "conmon.pid")
104
if runtimeChangeRequested && ctr.config.OCIRuntime != newRuntime {
105
logrus.Infof("Resetting container %s runtime to runtime %s", ctr.ID(), newRuntime)
106
ctr.config.OCIRuntime = newRuntime
107
ctr.ociRuntime = requestedRuntime
113
if err := r.state.RewriteContainerConfig(ctr, ctr.config); err != nil {
114
return fmt.Errorf("rewriting config for container %s: %w", ctr.ID(), err)
119
return r.stopPauseProcess()