mirror of
https://github.com/containers/podman.git
synced 2025-05-21 17:16:22 +08:00
system: move MovePauseProcessToScope to utils
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -3,12 +3,10 @@ package abi
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/containers/common/pkg/config"
|
"github.com/containers/common/pkg/config"
|
||||||
"github.com/containers/podman/v3/libpod/define"
|
"github.com/containers/podman/v3/libpod/define"
|
||||||
@ -114,14 +112,7 @@ func (ic *ContainerEngine) SetupRootless(_ context.Context, noMoveProcess bool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
became, ret, err = rootless.TryJoinFromFilePaths(pausePidPath, true, paths)
|
became, ret, err = rootless.TryJoinFromFilePaths(pausePidPath, true, paths)
|
||||||
|
utils.MovePauseProcessToScope(pausePidPath)
|
||||||
if err := movePauseProcessToScope(pausePidPath); err != nil {
|
|
||||||
if utils.RunsOnSystemd() {
|
|
||||||
logrus.Warnf("Failed to add pause process to systemd sandbox cgroup: %v", err)
|
|
||||||
} else {
|
|
||||||
logrus.Debugf("Failed to add pause process to systemd sandbox cgroup: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(errors.Wrapf(err, "invalid internal status, try resetting the pause process with %q", os.Args[0]+" system migrate"))
|
logrus.Error(errors.Wrapf(err, "invalid internal status, try resetting the pause process with %q", os.Args[0]+" system migrate"))
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -132,19 +123,6 @@ func (ic *ContainerEngine) SetupRootless(_ context.Context, noMoveProcess bool)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func movePauseProcessToScope(pausePidPath string) error {
|
|
||||||
data, err := ioutil.ReadFile(pausePidPath)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(err, "cannot read pause pid file")
|
|
||||||
}
|
|
||||||
pid, err := strconv.ParseUint(string(data), 10, 0)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(err, "cannot parse pid file %s", pausePidPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
return utils.RunUnderSystemdScope(int(pid), "user.slice", "podman-pause.scope")
|
|
||||||
}
|
|
||||||
|
|
||||||
// SystemPrune removes unused data from the system. Pruning pods, containers, volumes and images.
|
// SystemPrune removes unused data from the system. Pruning pods, containers, volumes and images.
|
||||||
func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.SystemPruneOptions) (*entities.SystemPruneReport, error) {
|
func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.SystemPruneOptions) (*entities.SystemPruneReport, error) {
|
||||||
var systemPruneReport = new(entities.SystemPruneReport)
|
var systemPruneReport = new(entities.SystemPruneReport)
|
||||||
|
@ -172,3 +172,28 @@ func RunsOnSystemd() bool {
|
|||||||
})
|
})
|
||||||
return runsOnSystemd
|
return runsOnSystemd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func moveProcessToScope(pidPath, slice, scope string) error {
|
||||||
|
data, err := ioutil.ReadFile(pidPath)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "cannot read pid file %s", pidPath)
|
||||||
|
}
|
||||||
|
pid, err := strconv.ParseUint(string(data), 10, 0)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "cannot parse pid file %s", pidPath)
|
||||||
|
}
|
||||||
|
return RunUnderSystemdScope(int(pid), slice, scope)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MovePauseProcessToScope moves the pause process used for rootless mode to keep the namespaces alive to
|
||||||
|
// a separate scope.
|
||||||
|
func MovePauseProcessToScope(pausePidPath string) {
|
||||||
|
err := moveProcessToScope(pausePidPath, "user.slice", "podman-pause.scope")
|
||||||
|
if err != nil {
|
||||||
|
if RunsOnSystemd() {
|
||||||
|
logrus.Warnf("Failed to add pause process to systemd sandbox cgroup: %v", err)
|
||||||
|
} else {
|
||||||
|
logrus.Debugf("Failed to add pause process to systemd sandbox cgroup: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user