Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

fix: resolve issues with cgroup2 and lxc4 #493

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions scripts/pipework
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,22 @@ CONTAINER_IFNAME=${CONTAINER_IFNAME:-eth1}

# Second step: find the guest (for now, we only support LXC containers)
while read _ mnt fstype options _; do
[ "$fstype" != "cgroup" ] && continue
echo "$options" | grep -qw devices || continue
[ "$fstype" != "cgroup2" ] && [ "$fstype" != "cgroup" ] && continue
if [ "$fstype" = "cgroup" ]; then
echo "$options" | grep -qw devices || continue
fi
CGROUPMNT=$mnt
CGROUPTYPE=$fstype
done < /proc/mounts

[ "$CGROUPMNT" ] || {
die 1 "Could not locate cgroup mount point."
}

# Try to find a cgroup matching exactly the provided name.
N=$(find "$CGROUPMNT" -name "$GUESTNAME" | wc -l)
[ "$CGROUPTYPE" = "cgroup" ] && N=$(find "$CGROUPMNT" -name "$GUESTNAME" | wc -l)
[ "$CGROUPTYPE" = "cgroup2" ] && N=$(find "$CGROUPMNT" -name "lxc.payload.$GUESTNAME" | wc -l)

case "$N" in
0)
# If we didn't find anything, try to lookup the container with Docker.
Expand Down Expand Up @@ -235,7 +240,8 @@ fi
if [ "$DOCKERPID" ]; then
NSPID=$DOCKERPID
else
NSPID=$(head -n 1 "$(find "$CGROUPMNT" -name "$GUESTNAME" | head -n 1)/tasks")
NSPATH=$(find "$CGROUPMNT" -name "$GUESTNAME" | head -n 1)
[ -f "$NSPATH/tasks" ] && NSPID=$(head -n 1 "$NSPATH/tasks")
[ "$NSPID" ] || {
# it is an alternative way to get the pid
NSPID=$(lxc-info -n "$GUESTNAME" | grep PID | grep -Eo '[0-9]+')
Expand Down