Created
August 9, 2011 00:24
-
-
Save tobert/1133130 to your computer and use it in GitHub Desktop.
side load cgroups into Debian init scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# put this fragment in a daemon's /etc/default/$NAME file to side-load | |
# putting that daemon into a cgroup automatically | |
ulimit -l unlimited | |
NOW=$(date +%s) | |
APPLICATION=$(basename $0 |sed -r -e 's/\.init$//' -e 's/-(dev|prod|staging|perf)$//') | |
INSTANCE=$(basename $0 |sed -r -e 's/\.init$//' -e 's/.*-(dev|prod|staging|perf)$/\1/') | |
# gross default that assumes unnamed instances are production | |
[ -n "$INSTANCE" -a "$INSTANCE" != "$APPLICATION" ] || INSTANCE="prod" | |
if [ -n "$APPLICATION" ] ; then | |
CG="/cgroup/${APPLICATION}" | |
if [ -n "$INSTANCE" ] ; then | |
CG="$CG-${INSTANCE}" | |
fi | |
if [ -d /cgroup -a -e /cgroup/tasks ] ; then | |
mkdir -p $CG | |
[ -n "$(cat $CG/cpuset.mems)" ] || cat /cgroup/cpuset.mems > $CG/cpuset.mems | |
[ -n "$(cat $CG/cpuset.cpus)" ] || cat /cgroup/cpuset.cpus > $CG/cpuset.cpus | |
# add this script's pid to tasks so subprocesses will be in the cg | |
echo $$ > $CG/tasks | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment