github.com/schwarzm/garden-linux@v0.0.0-20150507151835-33bca2147c47/old/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 [ ! -d $cgroup_path ]
    51  then
    52    mount_nested_cgroup $cgroup_path || \
    53      mount_flat_cgroup $cgroup_path
    54  fi
    55  
    56  ./net.sh setup
    57  
    58  # Disable AppArmor if possible
    59  if [ -x /etc/init.d/apparmor ]; then
    60    /etc/init.d/apparmor teardown
    61  fi
    62  
    63  # quotaon(8) exits with non-zero status when quotas are ENABLED
    64  if [ "$DISK_QUOTA_ENABLED" = "true" ] && quotaon -p $CONTAINER_DEPOT_MOUNT_POINT_PATH > /dev/null 2>&1
    65  then
    66    mount -o remount,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0 $CONTAINER_DEPOT_MOUNT_POINT_PATH
    67    quotacheck -ugmb -F vfsv0 $CONTAINER_DEPOT_MOUNT_POINT_PATH
    68    quotaon $CONTAINER_DEPOT_MOUNT_POINT_PATH
    69  elif [ "$DISK_QUOTA_ENABLED" = "false" ] && ! quotaon -p $CONTAINER_DEPOT_MOUNT_POINT_PATH > /dev/null 2>&1
    70  then
    71    quotaoff $CONTAINER_DEPOT_MOUNT_POINT_PATH
    72  fi