github.com/cloudfoundry-attic/garden-linux@v0.333.2-candidate/linux_backend/bin/setup.sh (about) 1 #!/bin/bash 2 3 [ -n "$DEBUG" ] && set -o xtrace 4 set -o nounset 5 set -o errexit 6 shopt -s nullglob 7 8 cd $(dirname "${0}") 9 10 cgroup_path="${GARDEN_CGROUP_PATH}" 11 12 function mount_flat_cgroup() { 13 cgroup_parent_path=$(dirname $1) 14 15 mkdir -p $cgroup_parent_path 16 17 if ! mountpoint -q $cgroup_parent_path; then 18 mount -t tmpfs none $cgroup_parent_path 19 fi 20 21 mkdir -p $1 22 mount -t cgroup cgroup $1 23 24 # bind-mount cgroup subsystems to make file tree consistent 25 for subsystem in $(tail -n +2 /proc/cgroups | awk '{print $1}'); do 26 mkdir -p ${1}/$subsystem 27 28 if ! mountpoint -q ${1}/$subsystem; then 29 mount --bind $1 ${1}/$subsystem 30 fi 31 done 32 } 33 34 function mount_nested_cgroup() { 35 mkdir -p $1 36 37 if ! mountpoint -q $1; then 38 mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup $1 39 fi 40 41 for subsystem in $(tail -n +2 /proc/cgroups | awk '{print $1}'); do 42 mkdir -p ${1}/$subsystem 43 44 if ! mountpoint -q ${1}/$subsystem; then 45 mount -n -t cgroup -o $subsystem cgroup ${1}/$subsystem 46 fi 47 done 48 } 49 50 if ! mountpoint -q $cgroup_path; then 51 mount_nested_cgroup $cgroup_path || \ 52 mount_flat_cgroup $cgroup_path 53 fi 54 55 ./net.sh setup 56 57 # Disable AppArmor if possible 58 if [ -x /etc/init.d/apparmor ]; then 59 /etc/init.d/apparmor teardown 60 fi