From 852880eff7be980c5bd4c86e8451a4e120a054a7 Mon Sep 17 00:00:00 2001 From: Balbir Singh Date: Mon, 14 Apr 2008 21:11:40 +0000 Subject: Add init scripts and a README. NOTE: These init scripts will change frequently and drastically. Signed-off-by: Balbir Singh git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/branches/balbir@14 4f4bb910-9a46-0410-90c8-c897d4f1cd53 --- scripts/README | 4 + scripts/doc/howto.txt | 62 ++++++++++++ scripts/etc/wlm.conf | 16 +++ scripts/etc/wlm/cpu.conf | 14 +++ scripts/init.d/wlm | 253 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 349 insertions(+) create mode 100644 scripts/README create mode 100644 scripts/doc/howto.txt create mode 100644 scripts/etc/wlm.conf create mode 100644 scripts/etc/wlm/cpu.conf create mode 100755 scripts/init.d/wlm (limited to 'scripts') diff --git a/scripts/README b/scripts/README new file mode 100644 index 0000000..8007b60 --- /dev/null +++ b/scripts/README @@ -0,0 +1,4 @@ +NOTE: These are temporary intermediate scripts, till libcg is up and running +on its own. The current parser works, but has a lot of band-aid around it. +We need a good cleanroom implementation of the parser. Doing so, would +enable us to build a good daemon and a set of init scripts around it. diff --git a/scripts/doc/howto.txt b/scripts/doc/howto.txt new file mode 100644 index 0000000..38c95e3 --- /dev/null +++ b/scripts/doc/howto.txt @@ -0,0 +1,62 @@ +initscripts - Initialization scripts; they are used to initialize the workload +management system. The script consists of two major components + +Configuration files +------------------- + +The main configuraiton file /etc/wlm.conf. This file has a format + +mount + + +A sample configuration file is included below + +# +# controller file +# +mount /container cpu +cpu /etc/wlm/cpu.conf + +NOTE: Any line beginning with '#' is ignored as comments. The sample +configuration above, mounts the cpu controller at mount point /container. +It then parses /etc/wlm/cpu.conf as the configuration file for the +cpu controller. + +The controller configuration file is of the format + + + +In the case of the CPU controller a sample configuration would look +like + +class1 cpu.shares=1024 +class2 cpu.shares=512 + +The configuration below creates two classes class1 and class2 and +assigns shares of 1024 to class1 and 512 to class1. + +Intialization script +-------------------- + +The initialization script is installed in /etc/init.d, it is called +"wlm". Depending on the run-level, it is installed in the appropriate +/etc/rc.d/rc.d. The script comes with two options + +a. start + +start, starts the workload management, parses the configuration file. +If required creates the mount point directory and then mounts the +cgroup filesystem with the controllers specified. + +b. stop + +stops workload management, moves all tasks from various groups to +the root class. It then removes all other classes and then unmounts +the workload management system. + +Assumptions +----------- + +1. The kernel is compiled in with the correct options to support + cgroups and the CPU controller. +2. This version has been tested with 2.6.24-rc1 only. diff --git a/scripts/etc/wlm.conf b/scripts/etc/wlm.conf new file mode 100644 index 0000000..01a12b3 --- /dev/null +++ b/scripts/etc/wlm.conf @@ -0,0 +1,16 @@ +# +# Copyright IBM Corporation. 2008 +# +# Authors: Balbir Singh +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2.1 of the GNU Lesser General Public License +# as published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# controller file +# +mount /tmp/container cpu +cpu /etc/wlm/cpu.conf diff --git a/scripts/etc/wlm/cpu.conf b/scripts/etc/wlm/cpu.conf new file mode 100644 index 0000000..10ac391 --- /dev/null +++ b/scripts/etc/wlm/cpu.conf @@ -0,0 +1,14 @@ +# +# Copyright IBM Corporation. 2008 +# +# Authors: Balbir Singh +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2.1 of the GNU Lesser General Public License +# as published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +class1 cpu.shares=1024 tuid=balbir tgid=balbir cuid=root cgid=root +class2 cpu.shares=512 tuid=root tgid=root cuid=balbir cgid=balbir diff --git a/scripts/init.d/wlm b/scripts/init.d/wlm new file mode 100755 index 0000000..ed463f6 --- /dev/null +++ b/scripts/init.d/wlm @@ -0,0 +1,253 @@ +# +# Start/Stop the workload manager +# +# Copyright IBM Corporation. 2008 +# +# Authors: Balbir Singh +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2.1 of the GNU Lesser General Public License +# as published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# +# TODO: Make this code more robust, add error checking and recovery +# for invalid configuration or interrupted execution +# +# Make the script LSB compliant +# + +CONF_FILE=/etc/wlm.conf +PROC_CGROUPS_FILE=/proc/cgroups +CGROUP_FS=cgroup +MOUNT_POINT=/dev/container +#MOUNT_OPTS=cpu +IGNORE_OPTS="ns cpuset" + +parse_controller_file() { + ctlr=$1 + file=$2 + tuid="root" + tgid="root" + cuid="root" + cgid="root" + + pushd $PWD 2>&1 > /dev/null + while read name opts + do + case $name in + 'mount') + ;; + *) + echo "Creating class $name" + class=$name + mkdir -p $MOUNTPOINT/$class + cd $MOUNTPOINT/$class + + if echo $opts | grep -q "=" + then + for single_opt in $opts + do + cf=`echo $single_opt | cut -d '=' -f1` + co=`echo $single_opt | cut -d '=' -f2` + case $cf in + "tuid") + tuid=$co + ;; + "cuid") + cuid=$co + ;; + "tgid") + tgid=$co + ;; + "cgid") + cgid=$co + ;; + *) + echo -n $co > $cf + ;; + esac + done + chown -R $cuid:$cgid $MOUNTPOINT/$class + chown -R $tuid:$tgid $MOUNTPOINT/$class/tasks + fi + esac + done < $file + popd 2>&1 > /dev/null +} + +parse_controller_opts() { + name=$1; + file=$2; + + if [ ! -r $PROC_CGROUPS_FILE ] + then + echo "$PROC_CGROUPS_FILE does not exist, please compile" + echo "cgroups into the kernel" + exit 1 + else + line=`grep -w $name $PROC_CGROUPS_FILE` + if [ $? -ne 0 ] + then + echo "$name controller not enabled" + exit 1 + fi + + active=`echo $line | awk '{print $2}'` + if [[ $active -eq 0 ]] + then + echo "$name controller not mounted" + else + parse_controller_file $name $file + fi + fi +} + +parse_conf_file() { + while read name conf + do + # skip all comments + if ! echo $name | grep -q ^# + then + case $name in + 'mount') + MOUNTPOINT=`echo $conf | cut -d ' ' -f1`; + MOUNTOPTS=`echo $conf | cut -d ' ' -f2`; + ;; + esac + fi + done < $CONF_FILE + + return 0; +} + +mount_fs() { + if [ ! -r $PROC_CGROUPS_FILE ] + then + echo "$PROC_CGROUPS_FILE does not exist, please compile" + echo "cgroups into the kernel" + exit 1 + else + while read name hierarchy num_cgroups + do + if ! echo $name | grep -q ^# + then + echo $IGNORE_OPTS | grep -wq $name + if [[ $? -ne 0 ]] + then + MOUNT_OPTS=$name","$MOUNT_OPTS + fi + fi + done < $PROC_CGROUPS_FILE + MOUNT_OPTS=${MOUNT_OPTS%%","} + #line=`grep -w $MOUNT_OPTS $PROC_CGROUPS_FILE` + #if [ $? -ne 0 ] + #then + # echo "$name controller not enabled" + # exit 1 + #fi + fi + mkdir -p $MOUNTPOINT + mount -t $CGROUP_FS $CGROUP_FS -o $MOUNT_OPTS $MOUNTPOINT + # + # Give root tasks read/write permission to all, since tasks + # tasks will be moved to root frequently + # + chmod ago+rwx $MOUNTPOINT/tasks + chmod ago+rwx $MOUNTPOINT + chmod +t $MOUNTPOINT + return $? +} + +umount_fs() { + umount $MOUNTPOINT + rmdir $MOUNTPOINT +} + +create_classes() { + while read name conf + do + # skip all comments + if ! echo $name | grep -q ^# + then + case $name in + 'mount') + ;; + *) + parse_controller_opts $name $conf + esac + fi + + done < $CONF_FILE +} + +start() { + echo "Starting wlm service: " + mount_fs + if [ $? -eq 0 ] + then + create_classes + fi + [ $? == 0 ] && touch /var/lock/subsys/wlm + return $? +} + +move_all_to_init_class() { + cd $MOUNTPOINT + cat /proc/mounts | grep -w $MOUNTPOINT + if [ $? -ne 0 ] + then + echo "resource control filesystem not mounted" + exit 1 + fi + + for i in `find . -type d` + do + case $i in + '.') + ;; + *) + class=${i#./*} + echo "Removing class $class" + sed -nu p < ./$i/tasks > tasks + rmdir $i + ;; + esac + done + cd - > /dev/null +} + + +stop() { + move_all_to_init_class + umount_fs +} + +trapped() { + # + # Do nothing + # + true +} + +# +# main script work done here +# +trap "trapped ABRT" ABRT +trap "trapped QUIT" QUIT +trap "trapped TERM" TERM +trap "trapped INT" INT + +parse_conf_file + +case $1 in + 'start') + start; + ;; + 'stop') + stop; + ;; +esac + -- cgit From 00e35b2d6a970edbb790b901fb7499f0f85e91b3 Mon Sep 17 00:00:00 2001 From: Balbir Singh Date: Wed, 16 Apr 2008 11:29:24 +0000 Subject: Fixed an initscripts problem. Comments were not ignored in the second level configuration file (i.e. cpu.conf) wlm | 65 ++++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 31 deletions(-) Signed-off-by: Balbir Singh git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/branches/balbir@16 4f4bb910-9a46-0410-90c8-c897d4f1cd53 --- scripts/init.d/wlm | 65 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 31 deletions(-) (limited to 'scripts') diff --git a/scripts/init.d/wlm b/scripts/init.d/wlm index ed463f6..d4e1dd7 100755 --- a/scripts/init.d/wlm +++ b/scripts/init.d/wlm @@ -41,37 +41,40 @@ parse_controller_file() { 'mount') ;; *) - echo "Creating class $name" - class=$name - mkdir -p $MOUNTPOINT/$class - cd $MOUNTPOINT/$class - - if echo $opts | grep -q "=" + if ! echo $name | grep -q ^# then - for single_opt in $opts - do - cf=`echo $single_opt | cut -d '=' -f1` - co=`echo $single_opt | cut -d '=' -f2` - case $cf in - "tuid") - tuid=$co - ;; - "cuid") - cuid=$co - ;; - "tgid") - tgid=$co - ;; - "cgid") - cgid=$co - ;; - *) - echo -n $co > $cf - ;; - esac - done - chown -R $cuid:$cgid $MOUNTPOINT/$class - chown -R $tuid:$tgid $MOUNTPOINT/$class/tasks + echo "Creating class $name" + class=$name + mkdir -p $MOUNTPOINT/$class + cd $MOUNTPOINT/$class + + if echo $opts | grep -q "=" + then + for single_opt in $opts + do + cf=`echo $single_opt | cut -d '=' -f1` + co=`echo $single_opt | cut -d '=' -f2` + case $cf in + "tuid") + tuid=$co + ;; + "cuid") + cuid=$co + ;; + "tgid") + tgid=$co + ;; + "cgid") + cgid=$co + ;; + *) + echo -n $co > $cf + ;; + esac + done + chown -R $cuid:$cgid $MOUNTPOINT/$class + chown -R $tuid:$tgid $MOUNTPOINT/$class/tasks + fi fi esac done < $file @@ -196,7 +199,7 @@ start() { move_all_to_init_class() { cd $MOUNTPOINT - cat /proc/mounts | grep -w $MOUNTPOINT + cat /proc/mounts | grep -wq $MOUNTPOINT if [ $? -ne 0 ] then echo "resource control filesystem not mounted" -- cgit From 5ddac5d87d47ace625a04146b91eed6c1ef9daea Mon Sep 17 00:00:00 2001 From: Balbir Singh Date: Fri, 18 Apr 2008 05:34:12 +0000 Subject: Miscellaneous scripts and libcg bug fixes Turn off -DDEBUG in Makefile Signed-off-by: Sudhir Kumar Signed-off-by: Balbir Singh git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/branches/balbir@18 4f4bb910-9a46-0410-90c8-c897d4f1cd53 --- scripts/doc/howto.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'scripts') diff --git a/scripts/doc/howto.txt b/scripts/doc/howto.txt index 38c95e3..c6796d6 100644 --- a/scripts/doc/howto.txt +++ b/scripts/doc/howto.txt @@ -35,6 +35,20 @@ class2 cpu.shares=512 The configuration below creates two classes class1 and class2 and assigns shares of 1024 to class1 and 512 to class1. +The other options that can be specified are + +tuid = owner of the tasks file +tgid = group permissions of the tasks file +cuid = owner of the newly created node +cgid = group permissions of the newly created node + +Example + +class1 cpu.shares = 1024 tuid=root tgid=root cuid=database cgid=database. + +By default all these files are owned by root. The flexibilty of specifying +owners makes it easier for other applications to use resource management. + Intialization script -------------------- -- cgit From 283955a35cef907323348a74ba9e58e342e2d56d Mon Sep 17 00:00:00 2001 From: Balbir Singh Date: Sat, 17 May 2008 11:38:53 +0000 Subject: Implement multiple mount point support Signed-off-by: Balbir Singh git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/branches/balbir@29 4f4bb910-9a46-0410-90c8-c897d4f1cd53 --- scripts/init.d/wlm | 202 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 117 insertions(+), 85 deletions(-) (limited to 'scripts') diff --git a/scripts/init.d/wlm b/scripts/init.d/wlm index d4e1dd7..65d51bd 100755 --- a/scripts/init.d/wlm +++ b/scripts/init.d/wlm @@ -22,10 +22,14 @@ CONF_FILE=/etc/wlm.conf PROC_CGROUPS_FILE=/proc/cgroups CGROUP_FS=cgroup -MOUNT_POINT=/dev/container -#MOUNT_OPTS=cpu IGNORE_OPTS="ns cpuset" +# support multiple mount points + +declare -a MOUNTPOINT +declare -a MOUNTOPTS +maxindex=0 + parse_controller_file() { ctlr=$1 file=$2 @@ -45,36 +49,41 @@ parse_controller_file() { then echo "Creating class $name" class=$name - mkdir -p $MOUNTPOINT/$class - cd $MOUNTPOINT/$class + index=1 + for i in `seq 1 $maxindex` + do + echo "mount pt ${MOUNTPOINT[$i]}" + mkdir -p ${MOUNTPOINT[$i]}/$class + cd ${MOUNTPOINT[$i]}/$class - if echo $opts | grep -q "=" - then - for single_opt in $opts - do - cf=`echo $single_opt | cut -d '=' -f1` - co=`echo $single_opt | cut -d '=' -f2` - case $cf in - "tuid") - tuid=$co - ;; - "cuid") - cuid=$co - ;; - "tgid") - tgid=$co - ;; - "cgid") - cgid=$co - ;; - *) - echo -n $co > $cf - ;; - esac - done - chown -R $cuid:$cgid $MOUNTPOINT/$class - chown -R $tuid:$tgid $MOUNTPOINT/$class/tasks - fi + if echo $opts | grep -q "=" + then + for single_opt in $opts + do + cf=`echo $single_opt | cut -d '=' -f1` + co=`echo $single_opt | cut -d '=' -f2` + case $cf in + "tuid") + tuid=$co + ;; + "cuid") + cuid=$co + ;; + "tgid") + tgid=$co + ;; + "cgid") + cgid=$co + ;; + *) + echo -n $co > $cf + ;; + esac + done + chown -R $cuid:$cgid ${MOUNTPOINT[$i]}/$class + chown -R $tuid:$tgid ${MOUNTPOINT[$i]}/$class/tasks + fi + done fi esac done < $file @@ -116,8 +125,9 @@ parse_conf_file() { then case $name in 'mount') - MOUNTPOINT=`echo $conf | cut -d ' ' -f1`; - MOUNTOPTS=`echo $conf | cut -d ' ' -f2`; + maxindex=$(($maxindex+1)) + MOUNTPOINT[$maxindex]=`echo $conf | cut -d ' ' -f1`; + MOUNTOPTS[$maxindex]=`echo $conf | cut -d ' ' -f2`; ;; esac fi @@ -132,19 +142,19 @@ mount_fs() { echo "$PROC_CGROUPS_FILE does not exist, please compile" echo "cgroups into the kernel" exit 1 - else - while read name hierarchy num_cgroups - do - if ! echo $name | grep -q ^# - then - echo $IGNORE_OPTS | grep -wq $name - if [[ $? -ne 0 ]] - then - MOUNT_OPTS=$name","$MOUNT_OPTS - fi - fi - done < $PROC_CGROUPS_FILE - MOUNT_OPTS=${MOUNT_OPTS%%","} + #else + #while read name hierarchy num_cgroups + #do + # if ! echo $name | grep -q ^# + # then + # echo $IGNORE_OPTS | grep -wq $name + # if [[ $? -ne 0 ]] + # then + # MOUNT_OPTS=$name","$MOUNT_OPTS + # fi + # fi + #done < $PROC_CGROUPS_FILE + #MOUNT_OPTS=${MOUNT_OPTS%%","} #line=`grep -w $MOUNT_OPTS $PROC_CGROUPS_FILE` #if [ $? -ne 0 ] #then @@ -152,21 +162,28 @@ mount_fs() { # exit 1 #fi fi - mkdir -p $MOUNTPOINT - mount -t $CGROUP_FS $CGROUP_FS -o $MOUNT_OPTS $MOUNTPOINT - # - # Give root tasks read/write permission to all, since tasks - # tasks will be moved to root frequently - # - chmod ago+rwx $MOUNTPOINT/tasks - chmod ago+rwx $MOUNTPOINT - chmod +t $MOUNTPOINT + for i in `seq 1 $maxindex` + do + mkdir -p ${MOUNTPOINT[$i]} + echo "mounting ${MOUNTPOINT[$i]} with ${MOUNTOPTS[$i]}" + mount -t $CGROUP_FS $CGROUP_FS -o ${MOUNTOPTS[$i]} ${MOUNTPOINT[$i]} + # + # Give root tasks read/write permission to all, since tasks + # tasks will be moved to root frequently + # + chmod ago+rwx ${MOUNTPOINT[$i]}/tasks + chmod ago+rwx ${MOUNTPOINT[$i]} + chmod +t ${MOUNTPOINT[$i]} + done return $? } umount_fs() { - umount $MOUNTPOINT - rmdir $MOUNTPOINT + for i in `seq 1 $maxindex` + do + umount ${MOUNTPOINT[$i]} + rmdir ${MOUNTPOINT[$i]} + done } create_classes() { @@ -198,28 +215,31 @@ start() { } move_all_to_init_class() { - cd $MOUNTPOINT - cat /proc/mounts | grep -wq $MOUNTPOINT - if [ $? -ne 0 ] - then - echo "resource control filesystem not mounted" - exit 1 - fi - - for i in `find . -type d` + for i in `seq 1 $maxindex` do - case $i in - '.') - ;; - *) - class=${i#./*} - echo "Removing class $class" - sed -nu p < ./$i/tasks > tasks - rmdir $i - ;; - esac + cd ${MOUNTPOINT[$i]} + cat /proc/mounts | grep -wq ${MOUNTPOINT[$i]} + if [ $? -ne 0 ] + then + echo "resource control filesystem not mounted" + exit 1 + fi + + for i in `find . -type d` + do + case $i in + '.') + ;; + *) + class=${i#./*} + echo "Removing class $class" + sed -nu p < ./$i/tasks > tasks + rmdir $i + ;; + esac + done + cd - > /dev/null done - cd - > /dev/null } @@ -235,22 +255,34 @@ trapped() { true } -# -# main script work done here -# -trap "trapped ABRT" ABRT -trap "trapped QUIT" QUIT -trap "trapped TERM" TERM -trap "trapped INT" INT +usage() { + echo "$0 " + exit 1 +} -parse_conf_file +common() { + # + # main script work done here + # + trap "trapped ABRT" ABRT + trap "trapped QUIT" QUIT + trap "trapped TERM" TERM + trap "trapped INT" INT + + parse_conf_file +} case $1 in 'start') + common start; ;; 'stop') + common stop; ;; + *) + usage + ;; esac -- cgit From 6b0384f40a1eb8ff70b27b6dfed3553883c9141f Mon Sep 17 00:00:00 2001 From: Balbir Singh Date: Sat, 24 May 2008 11:08:57 +0000 Subject: Add v0.1b tag git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/tags/v0.1b@49 4f4bb910-9a46-0410-90c8-c897d4f1cd53 --- scripts/etc/wlm/cpuacct.conf | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 scripts/etc/wlm/cpuacct.conf (limited to 'scripts') diff --git a/scripts/etc/wlm/cpuacct.conf b/scripts/etc/wlm/cpuacct.conf new file mode 100644 index 0000000..10ac391 --- /dev/null +++ b/scripts/etc/wlm/cpuacct.conf @@ -0,0 +1,14 @@ +# +# Copyright IBM Corporation. 2008 +# +# Authors: Balbir Singh +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2.1 of the GNU Lesser General Public License +# as published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +class1 cpu.shares=1024 tuid=balbir tgid=balbir cuid=root cgid=root +class2 cpu.shares=512 tuid=root tgid=root cuid=balbir cgid=balbir -- cgit