aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--testing/libcgroup/APKBUILD89
-rw-r--r--testing/libcgroup/cgconfig.confd4
-rw-r--r--testing/libcgroup/cgconfig.initd120
-rw-r--r--testing/libcgroup/cgred.confd17
-rw-r--r--testing/libcgroup/cgred.initd34
5 files changed, 264 insertions, 0 deletions
diff --git a/testing/libcgroup/APKBUILD b/testing/libcgroup/APKBUILD
new file mode 100644
index 0000000000..4268781ebd
--- /dev/null
+++ b/testing/libcgroup/APKBUILD
@@ -0,0 +1,89 @@
+# Contributor: Natanael Copa <ncopa@alpinelinux.org>
+# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
+pkgname=libcgroup
+pkgver=0.38
+pkgrel=0
+pkgdesc="Library to control and monitor control groups"
+url="http://libcg.sourceforge.net/"
+arch="all"
+license="LGPLv2+"
+depends=""
+depends_dev=""
+makedepends="$depends_dev bison flex linux-pam-dev"
+install=""
+subpackages="$pkgname-dev $pkgname-doc $pkgname-tools $pkgname-pam"
+source="http://downloads.sourceforge.net/libcg/libcgroup-$pkgver.tar.bz2
+ cgconfig.initd
+ cgconfig.confd
+ cgred.initd
+ cgred.confd
+ "
+
+_builddir="$srcdir"/libcgroup-$pkgver
+prepare() {
+ local i
+ cd "$_builddir"
+ for i in $source; do
+ case $i in
+ *.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
+ esac
+ done
+ sed -e 's:/etc/cgrules.conf:/etc/cgroup/cgrules.conf:' \
+ -i src/libcgroup-internal.h || return 1
+}
+
+build() {
+ cd "$_builddir"
+ ./configure --prefix=/usr \
+ --enable-shared \
+ --enable-daemon \
+ --enable-tools \
+ || return 1
+ make || return 1
+}
+
+package() {
+ local _sysconfdir="$pkgdir"/etc
+ cd "$_builddir"
+ make DESTDIR="$pkgdir" install || return 1
+ rm -f "$pkgdir"/usr/lib/*.la \
+ "$pkgdir"/usr/lib/security/pam_cgroup.la || return 1
+
+ # config files
+ install -d "$_sysconfdir"
+ install -m 644 samples/cgconfig.conf "$_sysconfdir"/cgconfig.conf \
+ || return 1
+ install -m 644 samples/cgrules.conf "$_sysconfdir"/cgrules.conf \
+ || return 1
+ install -m 644 samples/cgsnapshot_blacklist.conf \
+ "$_sysconfdir"/cgsnapshot_blacklist.conf || return 1
+
+ # init scripts
+ for i in $source; do
+ case $i in
+ *.initd) install -Dm755 "$srcdir"/$i \
+ "$pkgdir"/etc/init.d/${i%.*} || return 1;;
+ *.confd) install -Dm644 "$srcdir"/$i \
+ "$pkgdir"/etc/conf.d/${i%.*} || return 1;;
+ esac
+ done
+}
+
+tools() {
+ pkgdesc="Command-line utility programs, services and daemons for libcgroup"
+ install -d "$subpkgdir"/usr
+ mv "$pkgdir"/usr/bin "$pkgdir"/usr/sbin "$subpkgdir"/usr/
+ mv "$pkgdir"/etc "$subpkgdir"/
+}
+
+pam() {
+ pkgdesc="A Pluggable Authentication Module for libcgroup"
+ install -d "$subpkgdir"/usr/lib
+ mv "$pkgdir"/usr/lib/security "$subpkgdir"/usr/lib/
+}
+
+md5sums="f0f7d4060bf36ccc19d75dbf4f1695db libcgroup-0.38.tar.bz2
+3fa43b95417d491450c8fe239fca8557 cgconfig.initd
+7743c134ead2422fbd375447c4c9654c cgconfig.confd
+8bb3ca45c5ba91d4078e738978afb54d cgred.initd
+f36926f1a968d3ee5fd7f0d7a6a7167e cgred.confd"
diff --git a/testing/libcgroup/cgconfig.confd b/testing/libcgroup/cgconfig.confd
new file mode 100644
index 0000000000..e41730ae0e
--- /dev/null
+++ b/testing/libcgroup/cgconfig.confd
@@ -0,0 +1,4 @@
+# /etc/conf.d/cgconfig: config file for /etc/init.d/cgconfig
+
+# Configuration file location
+#CONFIG_FILE=/etc/cgroup/cgconfig.conf
diff --git a/testing/libcgroup/cgconfig.initd b/testing/libcgroup/cgconfig.initd
new file mode 100644
index 0000000000..8abf245278
--- /dev/null
+++ b/testing/libcgroup/cgconfig.initd
@@ -0,0 +1,120 @@
+#!/sbin/runscript
+#
+# Control Groups Configuration Startup
+#
+# This script runs the cgconfigparser utility to parse and setup
+# the control group filesystem. It uses ${CONFIG_FILE}
+# and parses the configuration specified in there.
+#
+CGCONFIGPARSER="/usr/sbin/cgconfigparser"
+CGROUP_FS="cgroup"
+CONFIG_FILE=${CONFIG_FILE:-"/etc/cgconfig.conf"}
+MOUNTS_FILE="/proc/mounts"
+RULES_FILE="/etc/cgrules.conf"
+
+# Support multiple mount points
+MOUNT_POINTS=
+
+move_all_to_init_class() {
+ local i
+ for i in $MOUNT_POINTS; do
+ local mount_point=${i%:*}
+ cd ${mount_point}
+
+ if grep -qw "${mount_point}" ${MOUNTS_FILE}; then
+ local directory
+ for directory in $(find . -depth -type d); do
+ if [ "${directory}" != "." ]; then
+ # cat fails with "Argument list too long" error
+ sed -nu p < ${directory}/tasks > tasks
+ rmdir ${directory}
+ fi
+ done
+ else
+ ewarn "Resource control filesystem not mounted"
+ fi
+
+ cd - >/dev/null
+ done
+}
+
+parse_mounts() {
+ local device mount_point fs_type options other
+ while read device mount_point fs_type options other; do
+ if echo ${CGROUP_FS} | grep -q ${device}; then
+ MOUNT_POINTS="${MOUNT_POINTS} ${mount_point}:${options}"
+ fi
+ done < ${MOUNTS_FILE}
+}
+
+umount_fs() {
+ local i
+ for i in ${MOUNT_POINTS}; do
+ umount ${i%:*}
+ rmdir ${i%:*}
+ done
+}
+
+depend() {
+ need local
+}
+
+start() {
+ ebegin "Starting cgconfig service"
+
+ # Mount filesystem and create cgroups
+ if ! ${CGCONFIGPARSER} -l ${CONFIG_FILE} >/dev/null; then
+ eend 1 "Failed to parse ${CONFIG_FILE}"
+ return 1
+ fi
+
+ parse_mounts
+
+ # Find default cgroup name in rules file
+ local default_cgroup
+ if [ -f "${RULES_FILE}" ]; then
+ default_cgroup=$(awk '$1 == "*" {print $3; exit}' ${RULES_FILE})
+ if [ $default_cgroup == "*" ]; then
+ ewarn "${RULES_FILE} incorrect"
+ ewarn "Overriding it"
+ default_cgroup=
+ fi
+ fi
+ # Use predefined name if none was found
+ if [ -z "${default_cgroup}" ]; then
+ default_cgroup=sysdefault
+ fi
+
+ # Create a default cgroup for tasks to return back to
+ local i
+ for i in $MOUNT_POINTS; do
+ local mount_point=${i%:*}
+ local mount_options=${i#*:}
+ # Ignore if directory already exists
+ mkdir -p ${mount_point}/${default_cgroup}
+ find ${mount_point}/ -name tasks | xargs chmod a+rw
+ chmod go-w ${mount_point}/tasks
+
+ # Special rule for cpusets
+ if echo ${mount_options} | grep -qw cpuset; then
+ cat ${mount_point}/cpuset.cpus > ${mount_point}/${default_cgroup}/cpuset.cpus
+ cat ${mount_point}/cpuset.mems > ${mount_point}/${default_cgroup}/cpuset.mems
+ fi
+
+ # Classify everything to default cgroup
+ local j
+ for j in $(ps --no-headers -eL o tid); do
+ echo $j > ${mount_point}/${default_cgroup}/tasks 2>/dev/null
+ done
+ done
+
+ eend 0
+}
+
+stop() {
+ ebegin "Stopping cgconfig service"
+ parse_mounts
+ move_all_to_init_class
+ umount_fs
+ eend 0
+}
diff --git a/testing/libcgroup/cgred.confd b/testing/libcgroup/cgred.confd
new file mode 100644
index 0000000000..663ffc0c7d
--- /dev/null
+++ b/testing/libcgroup/cgred.confd
@@ -0,0 +1,17 @@
+# /etc/conf.d/cgred.conf: config file for /etc/init.d/cgred
+
+# Uncomment the following line to log to specified file instead of syslog
+#LOG_FILE="/var/log/cgrulesengd.log"
+
+# Uncomment the second line to run CGroup Rules Engine in non-daemon mode
+#NODAEMON=""
+NODAEMON="--nodaemon"
+
+# Uncomment the second line to disable logging for CGroup Rules Engine
+# Uncomment the third line to enable more verbose logging.
+#LOG=""
+LOG="--nolog"
+#LOG="-v"
+
+# PID file
+PID_FILE=/var/run/cgred.pid
diff --git a/testing/libcgroup/cgred.initd b/testing/libcgroup/cgred.initd
new file mode 100644
index 0000000000..68c0af6752
--- /dev/null
+++ b/testing/libcgroup/cgred.initd
@@ -0,0 +1,34 @@
+#!/sbin/runscript
+#
+# CGroups Rules Engine Daemon
+#
+# This is a daemon for automatically classifying processes into cgroups based
+# on UID/GID.
+#
+extra_started_commands="reload"
+
+name="CGroup Rules Engine Daemon"
+command="/usr/sbin/cgrulesengd"
+pidfile=${PID_FILE:-"/var/run/cgred.pid"}
+command_args="${NODAEMON} ${LOG}"
+start_stop_daemon_args="--make-pidfile --background --stdout /dev/null"
+
+
+depend() {
+ need cgconfig
+ use logger
+}
+
+start_pre() {
+ if [ -n "${LOG_FILE}" ]; then
+ command_args="${command_args} --log-file=${LOG_FILE}"
+ fi
+}
+
+reload() {
+ ebegin "Reloading ${name}"
+ start-stop-daemon --signal USR2 --pidfile "${pidfile}" \
+ --exec "${command}"
+ eend $?
+}
+