Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 84 lines (67 sloc) 2.64 KB
#!/bin/sh -e
# We're dealing with mount entries, so expand any symlink
LXC_ROOTFS_MOUNT=$(readlink -f ${LXC_ROOTFS_MOUNT})
# /proc files
if [ -d @LXCFSTARGETDIR@/proc/ ]; then
for entry in @LXCFSTARGETDIR@/proc/*; do
[ -e "${LXC_ROOTFS_MOUNT}/proc/$(basename $entry)" ] || continue
mount -n --bind $entry ${LXC_ROOTFS_MOUNT}/proc/$(basename $entry)
done
fi
# Allow nesting lxcfs
if [ -d ${LXC_ROOTFS_MOUNT}@LXCFSTARGETDIR@/ ]; then
mount -n --bind @LXCFSTARGETDIR@ ${LXC_ROOTFS_MOUNT}@LXCFSTARGETDIR@/
fi
# no need for lxcfs cgroups if we have cgroup namespaces
[ -n "$LXC_CGNS_AWARE" ] && [ -f /proc/self/ns/cgroup ] && exit 0
# Don't mess with containers that don't have /sys/fs/cgroup configured
# (lxc.mount.auto = cgroup:mixed)
if touch ${LXC_ROOTFS_MOUNT}/sys/fs/cgroup/lxcfs; then
rm ${LXC_ROOTFS_MOUNT}/sys/fs/cgroup/lxcfs
else
exit 0
fi
# /sys/fs/cgroup files
if [ -d "${LXC_ROOTFS_MOUNT}/sys/fs/cgroup" ]; then
if [ -d @LXCFSTARGETDIR@/cgroup ]; then
# Cleanup existing mounts
for entry in ${LXC_ROOTFS_MOUNT}/sys/fs/cgroup/*; do
DEST=$(basename $entry)
if [ "${DEST}" = "cgmanager" ]; then
continue
fi
if [ ! -d "${LXC_ROOTFS_MOUNT}/sys/fs/cgroup/${DEST}" ]; then
continue
fi
while grep -q "${LXC_ROOTFS_MOUNT}/sys/fs/cgroup/${DEST}" /proc/self/mountinfo; do
grep "${LXC_ROOTFS_MOUNT}/sys/fs/cgroup/${DEST}" /proc/self/mountinfo | cut -d' ' -f5 | while read line; do
[ -e "${line}" ] && umount -l "${line}" || true
done
done
rm -Rf ${LXC_ROOTFS_MOUNT}/sys/fs/cgroup/${DEST}
done
# Mount the new entries
for entry in @LXCFSTARGETDIR@/cgroup/*; do
DEST=$(basename $entry)
if [ "$DEST" = "name=systemd" ]; then
DEST="systemd"
fi
if [ ! -d ${LXC_ROOTFS_MOUNT}/sys/fs/cgroup/${DEST} ]; then
mkdir ${LXC_ROOTFS_MOUNT}/sys/fs/cgroup/${DEST}
fi
mount -n --bind $entry ${LXC_ROOTFS_MOUNT}/sys/fs/cgroup/$DEST
# make sure that cpu,cpuacct shows up as cpu and cpuacct
# separately, else systemd is unhappy
if echo $DEST | grep -q ","; then
arr=$(echo $DEST | tr "," "\n")
for single in $arr
do
if [ ! -L ${LXC_ROOTFS_MOUNT}/sys/fs/cgroup/$single ]; then
ln -s $DEST ${LXC_ROOTFS_MOUNT}/sys/fs/cgroup/$single
fi
done
fi
done
fi
fi
exit 0