Cleaned up cgroup implementation

Set default limits to 1 core and 512MB, CGX has also been removed to try
and make it more clear what is calling what.
This commit is contained in:
Peter Wilmott 2015-07-31 19:35:42 +00:00
parent bc1b4719b5
commit 1f48b32c42

9
bocker
View File

@ -1,7 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -o errexit -o nounset -o pipefail; shopt -s nullglob set -o errexit -o nounset -o pipefail; shopt -s nullglob
btrfs_path='/var/bocker' btrfs_path='/var/bocker'; cgroups='cpu,cpuacct,cpuset,memory';
cgroups='cpu,cpuacct,cpuset,memory'; $(cgget -h &> /dev/null) && CGX="cgexec -g $cgroups" || CGX='_='
function bocker_check() { function bocker_check() {
btrfs subvolume list "$btrfs_path" | grep -qw "$1" && echo 0 || echo 1 btrfs subvolume list "$btrfs_path" | grep -qw "$1" && echo 0 || echo 1
@ -76,8 +75,10 @@ function bocker_run() { #HELP Create a container:\nBOCKER run <image_id> <comman
btrfs subvolume snapshot "$btrfs_path/$1" "$btrfs_path/$uuid" > /dev/null btrfs subvolume snapshot "$btrfs_path/$1" "$btrfs_path/$uuid" > /dev/null
echo 'nameserver 8.8.8.8' > "$btrfs_path/$uuid"/etc/resolv.conf echo 'nameserver 8.8.8.8' > "$btrfs_path/$uuid"/etc/resolv.conf
echo "$cmd" > "$btrfs_path/$uuid/$uuid.cmd" echo "$cmd" > "$btrfs_path/$uuid/$uuid.cmd"
cgcreate -g $cgroups:/$uuid && cgset -r cpuset.cpus=0-$(($(grep vendor_id /proc/cpuinfo | wc -l)-1)) $uuid && cgset -r cpuset.mems=0 $uuid &> /dev/null || true cgcreate -g "$cgroups:/$uuid"
$CGX:$uuid ip netns exec netns_"$uuid" "unshare" -fmuip --mount-proc "chroot" \ cgset -r cpuset.cpus=0-1 "$uuid" && cgset -r cpuset.mems=0 "$uuid"
cgset -r memory.limit_in_bytes=512000000 "$uuid"
cgexec -g "$cgroups:$uuid" ip netns exec netns_"$uuid" "unshare" -fmuip --mount-proc "chroot" \
"$btrfs_path/$uuid" /bin/sh -c "/bin/mount -t proc proc /proc && $cmd" \ "$btrfs_path/$uuid" /bin/sh -c "/bin/mount -t proc proc /proc && $cmd" \
2>&1 | tee "$btrfs_path/$uuid/$uuid.log" || true 2>&1 | tee "$btrfs_path/$uuid/$uuid.log" || true
ip link del dev veth0_"$uuid" ip link del dev veth0_"$uuid"