[Pkg-sysvinit-devel] Bug#601757: updated mountcgroupsubsys.sh
Marcus Osdoba
marcus.osdoba at googlemail.com
Sun Apr 22 09:56:01 UTC 2012
As an lxc user, I like a semi-automatic (distributional way) of setting
up the needed cgroup-subsystems.
Ubuntu uses a lightweight variant of cgroups-bin (currently blocked in
wheezy).
As always you may have more than one way to achive a proper cgroup handling.
Attached is my (updated) solution which is an initscript in parallel to
such as mountdevsubfs.sh and similar.
I use this on Squeeze-server running with latest lxc-7.5.x from Wheezy.
It was never tested together with systemd. All subsystems are mounted in
their own subdirectories.
Feel free to examine the functionality and reuse it in initscripts for
future cgroup handling in wheezy.
-------------- next part --------------
#! /bin/sh
### BEGIN INIT INFO
# Provides: mountcgroupsubsys
# Required-Start: mountkernfs
# Required-Stop:
# Should-Start:
# Default-Start: S
# Default-Stop:
# Short-Description: Mount cgroup subsystems
# Description: Mounts every cgroup subsystem
# in it's own directory under /sys/fs/cgroup
### END INIT INFO
PATH=/sbin:/bin
. /lib/init/vars.sh
. /lib/lsb/init-functions
. /lib/init/mount-functions.sh
[ -f /etc/default/tmpfs ] && . /etc/default/tmpfs
CGROUP_MOUNTTAB=/proc/mounts # /etc/mtab does not show cgroup subsystems after stop/start
export CGROUP_MOUNTTAB
do_start () {
#
# Mount cgroup on /sys/fs/cgroup
#
# Only mount cgroup if it is supported and enabled in /etc/default/tmpfs
if grep -E -qs "cgroup\$" /proc/filesystems && [ -d /sys/fs/cgroup ] && [ yes = "$CGROUPSUBSYSTEMS" ]
then
RW_OPT=
[ "${RW_SIZE:=$TMPFS_SIZE}" ] && RW_OPT=",size=$RW_SIZE"
domount tmpfs "" /sys/fs/cgroup tmpfs -omode=0755,nosuid$RW_OPT
CGROUP_EXCL_SUBSYS=${CGROUP_EXCL_SUBSYS:-"ns"} # ns (namespace) subsystem marked as deprecated
grep -v "^#" /proc/cgroups | while read subsysline; do
subsys=$(echo $subsysline | /usr/bin/awk '{print $1}' )
subsys_enabled=$(echo $subsysline | /usr/bin/awk '{print $4}' )
if [ ! -d /sys/fs/cgroup/${subsys} -a "$subsys_enabled" = "1" ]
then
mkdir /sys/fs/cgroup/${subsys}
domount cgroup "" /sys/fs/cgroup/${subsys} cgroup -o${subsys}
[ $? -eq 0 ] && log_success_msg "Successfully mounted /sys/fs/cgroup/${subsys}."
else
log_warning_msg "Directory /sys/fs/cgroup/${subsys} does already exists or subsystem is not enabled. Do not try to mount cgroup subsystem named $subsys."
fi
done
else
log_warning_msg "Cgroups not supported by kernel or CGROUPSUBSYSTEMS not set to 'yes' in /etc/default/tmpfs."
fi
}
do_stop () {
if [ -d /sys/fs/cgroup ]
then
for subsys in $(/usr/bin/awk '{print $1}' /proc/cgroups); do
if [ -d /sys/fs/cgroup/${subsys} ]
then
umount /sys/fs/cgroup/${subsys}
[ $? -ne 0 ] && log_warning_msg "Could not unmount /sys/fs/cgroup/${subsys}."
rmdir /sys/fs/cgroup/${subsys}
[ $? -eq 0 ] && log_success_msg "Successfully removed /sys/fs/cgroup/${subsys}."
fi
done
grep "/sys/fs/cgroup" $CGROUP_MOUNTTAB > /dev/null
if [ $? -eq 0 ]
then
umount /sys/fs/cgroup
[ $? -eq 0 ] && log_success_msg "Successfully unmounted /sys/fs/cgroup."
fi
else
log_warning_msg "Directory /sys/fs/cgroup not found. Do not try to unmount cgroup subsystems."
fi
}
do_status () {
grep "/sys/fs/cgroup" $CGROUP_MOUNTTAB > /dev/null
if [ -d /sys/fs/cgroup -a $? -eq 0 ]
then
for subsys in $(/usr/bin/awk '{print $1}' /proc/cgroups); do
if [ -d /sys/fs/cgroup/${subsys} ]
then
log_action_msg "Cgroup subsystem ${subsys} found in /sys/fs/cgroup/${subsys}"
fi
done
else
log_action_msg "Did not find mounted /sys/fs/cgroup"
fi
}
case "$1" in
"")
echo "Warning: mountcgroupsubsys should be called with the 'start' argument." >&2
do_start
;;
start)
do_start
;;
status)
do_status
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
do_stop
;;
*)
echo "Usage: mountcgroupsubsys [start|stop]" >&2
exit 3
;;
esac
More information about the Pkg-sysvinit-devel
mailing list