]> git.proxmox.com Git - mirror_lxc.git/blob - hooks/mountcgroups
cgroups: don't mount under init's cgroup
[mirror_lxc.git] / hooks / mountcgroups
1 #!/bin/bash
2
3 # (C) Copyright Canonical 2011,2012
4
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 #
20 # This is an example hook to mount all mounted cgroups in the
21 # container. Only the container's own cgroup (not parents) will be
22 # accessible to the container. You can enable this by adding
23 # lxc.hook.mount = /usr/share/lxc/hooks/mountcgroups
24 # to your container's configuration file.
25
26 set -e
27
28 c=$1
29 d=/sys/fs/cgroup
30 d2=$LXC_ROOTFS_MOUNT/${d}
31 if [ ! -d "$d" ]; then
32 exit 0
33 fi
34
35 mount -n -t tmpfs tmpfs ${d2}
36
37 # XXX TODO - we'll need to account for other cgroup groups beside 'lxc',
38 # i.e. 'build' or 'users/joe'.
39 for dir in `/bin/ls $d`; do
40 mkdir -p "${d}/${dir}/lxc/${c}/${c}.real"
41 echo 1 > "${d}/${dir}/lxc/${c}/${c}.real/tasks"
42 mkdir -p ${d2}/${dir}
43 mount -n --bind "${d}/${dir}/lxc/${c}/${c}.real" "${d2}/${dir}"
44 done