From a9b0d34bb25cfec132fd5f910060e63686188abc Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Tue, 4 May 2021 19:26:21 +0200 Subject: [PATCH] fix: resolve issues with cgroup2 and lxc4 --- scripts/pipework | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/pipework b/scripts/pipework index 2438ca9..04bbd4b 100755 --- a/scripts/pipework +++ b/scripts/pipework @@ -144,9 +144,12 @@ 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" ] || { @@ -154,7 +157,9 @@ done < /proc/mounts } # 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. @@ -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]+')