mirror of
https://github.com/p8952/bocker.git
synced 2025-11-08 19:43:59 +01:00
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:
parent
bc1b4719b5
commit
1f48b32c42
9
bocker
9
bocker
@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
set -o errexit -o nounset -o pipefail; shopt -s nullglob
|
||||
btrfs_path='/var/bocker'
|
||||
cgroups='cpu,cpuacct,cpuset,memory'; $(cgget -h &> /dev/null) && CGX="cgexec -g $cgroups" || CGX='_='
|
||||
btrfs_path='/var/bocker'; cgroups='cpu,cpuacct,cpuset,memory';
|
||||
|
||||
function bocker_check() {
|
||||
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
|
||||
echo 'nameserver 8.8.8.8' > "$btrfs_path/$uuid"/etc/resolv.conf
|
||||
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
|
||||
$CGX:$uuid ip netns exec netns_"$uuid" "unshare" -fmuip --mount-proc "chroot" \
|
||||
cgcreate -g "$cgroups:/$uuid"
|
||||
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" \
|
||||
2>&1 | tee "$btrfs_path/$uuid/$uuid.log" || true
|
||||
ip link del dev veth0_"$uuid"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user