#!/bin/sh
# Copyright 2011 Canonical, Inc
# Author: Serge Hallyn <serge.hallyn@canonical.com>

# For simplicity this script provides no flexibility

# If /sys/fs/cgroup is mounted, we don't run again
if [ -n "`grep /sys/fs/cgroup /proc/mounts`" ]; then
	exit 0
fi

# kernel provides cgroups?
if [ ! -e /proc/cgroups ]; then
	exit 0
fi

mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup

# get list of cgroup controllers
for c in `tail -n +2 /proc/cgroups | awk '{ print $1 }'`; do
	mkdir /sys/fs/cgroup/$c
	mount -t cgroup -o $c cgroup /sys/fs/cgroup/$c
done

exit 0
