-
-
Save chussenot/d4f3524708e667b49bcdf76226651a45 to your computer and use it in GitHub Desktop.
cgroup u/mounting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu | |
function ensureMounted() { | |
source=$1 | |
shift | |
target=$1 | |
shift | |
type=$1 | |
shift | |
opts=${1:-} | |
mkdir -p "$target" | |
if grep -q "${target} " /proc/self/mounts; then | |
return 0 | |
fi | |
cmd="mount -t $type $source $target" | |
if [ -n "${opts:-}" ]; then | |
cmd="$cmd -o $opts" | |
fi | |
$cmd | |
} | |
function ensureUnmounted() { | |
point=$1 | |
shift | |
if grep -q "${point} " /proc/self/mounts; then | |
umount "$point" | |
fi | |
} | |
cgroot=/sys/fs/cgroup | |
if [ "${1:-}" == "destroy" ]; then | |
ensureUnmounted /cgroups | |
ensureUnmounted $cgroot/devices | |
ensureUnmounted $cgroot/cpuset | |
ensureUnmounted $cgroot/cpu | |
ensureUnmounted $cgroot/memory | |
ensureUnmounted $cgroot | |
exit 0 | |
fi | |
ensureMounted none $cgroot tmpfs | |
ensureMounted cgroup /cgroups cgroup cpu,memory # this will cause runc to break | |
ensureMounted cgroup $cgroot/devices cgroup devices | |
ensureMounted cgroup $cgroot/cpuset cgroup cpuset | |
ensureMounted cgroup $cgroot/cpu cgroup cpu,memory | |
ensureMounted cgroup $cgroot/memory cgroup cpu,memory |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment