Skip to content

Instantly share code, notes, and snippets.

@tobert
Created August 9, 2011 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobert/1133130 to your computer and use it in GitHub Desktop.
Save tobert/1133130 to your computer and use it in GitHub Desktop.
side load cgroups into Debian init scripts
# 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