From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 55280138A79 for ; Sat, 16 Feb 2013 07:30:53 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C6A95E0539; Sat, 16 Feb 2013 07:30:52 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 440EDE0539 for ; Sat, 16 Feb 2013 07:30:52 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 04EA8335E2B for ; Sat, 16 Feb 2013 07:30:51 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 52D39E4073 for ; Sat, 16 Feb 2013 07:30:48 +0000 (UTC) From: "William Hubbs" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "William Hubbs" Message-ID: <1360999715.b46747f9981337470353014bfa34e9f9f8bace34.WilliamH@OpenRC> Subject: [gentoo-commits] proj/openrc:master commit in: sh/ X-VCS-Repository: proj/openrc X-VCS-Files: sh/.gitignore sh/Makefile sh/rc-cgroup.sh.in sh/runscript.sh.in X-VCS-Directories: sh/ X-VCS-Committer: WilliamH X-VCS-Committer-Name: William Hubbs X-VCS-Revision: b46747f9981337470353014bfa34e9f9f8bace34 X-VCS-Branch: master Date: Sat, 16 Feb 2013 07:30:48 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 3697c948-19b0-4ccd-85ea-835ac28a9058 X-Archives-Hash: 01ecd6d8cf3d08b9c242388c5ebb69cf commit: b46747f9981337470353014bfa34e9f9f8bace34 Author: Alexander Vershilov gentoo org> AuthorDate: Sun Feb 3 22:01:16 2013 +0000 Commit: William Hubbs gentoo org> CommitDate: Sat Feb 16 07:28:35 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=b46747f9 Add module for cgroup processing sh/rc-cgroup.sh.in: new script to handle cgroup processing sh/rc-cgroup.sh.in: do not use grep or cut (modification by William Hubbs) sh/runscript.sh.in: use the cgroup script --- sh/.gitignore | 1 + sh/Makefile | 4 +- sh/rc-cgroup.sh.in | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ sh/runscript.sh.in | 26 ++++------------------ 4 files changed, 67 insertions(+), 23 deletions(-) diff --git a/sh/.gitignore b/sh/.gitignore index a07afb3..9fe5510 100644 --- a/sh/.gitignore +++ b/sh/.gitignore @@ -8,6 +8,7 @@ init.sh init-early.sh ifwatchd-carrier.sh ifwatchd-nocarrier.sh +rc-cgroup.sh udhcpc-hook.sh tmpfiles.sh migrate-to-run.sh diff --git a/sh/Makefile b/sh/Makefile index 356c37e..043b144 100644 --- a/sh/Makefile +++ b/sh/Makefile @@ -13,9 +13,9 @@ SRCS-FreeBSD= BIN-FreeBSD= SRCS-Linux= cgroup-release-agent.sh.in init-early.sh.in migrate-to-run.sh.in \ - udhcpc-hook.sh.in + rc-cgroup.sh.in udhcpc-hook.sh.in BIN-Linux= cgroup-release-agent.sh init-early.sh migrate-to-run.sh \ - udhcpc-hook.sh + rc-cgroup.sh udhcpc-hook.sh SRCS-NetBSD= ifwatchd-carrier.sh.in ifwatchd-nocarrier.sh.in BIN-NetBSD= ifwatchd-carrier.sh ifwatchd-nocarrier.sh diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in new file mode 100644 index 0000000..09b9b56 --- /dev/null +++ b/sh/rc-cgroup.sh.in @@ -0,0 +1,59 @@ +#@SHELL@ +# Copyright (c) 2012 Alexander Vershilov +# Released under the 2-clause BSD license. + +cgroup_find_path() +{ + local OIFS n name dir result + [ -n "$1" ] || return 0 + OIFS="$IFS" + IFS=":" + while read n name dir; do + [ "$name" = "$1" ] && result="$dir" + done < /proc/1/cgroup + IFS="$OIFS" + echo $result +} + +# prepare values to be attached inside cgroups +cgroup_prepare() +{ + local h=$(cgroup_find_path "$1") + cgroup="/sys/fs/cgroup/${1}${h}openrc_${RC_SVCNAME}" + [ -d ${cgroup} ] || mkdir -p ${cgroup} + return 0 +} + +cgroup_set_value() +{ + [ -f "$cgroup/${1}" -a -n "$2" ] && echo $2 > "${cgroup}/${1}" + return 0 +} + +cgroup_add_process() +{ + [ -f "${cgroup}"/tasks ] && echo 0 > "${cgroup}"/tasks + return 0 +} + +cgroup_set_limits() +{ + openrc_cgroup=/sys/fs/cgroup/openrc + if [ -d ${openrc_cgroup} ]; then + cgroup=${openrc_cgroup}/${RC_SVCNAME} + mkdir -p ${cgroup} + [ -f "${cgroup}"/tasks ] && echo 0 > "${cgroup}"/tasks + fi + + if [ -d /sys/fs/cgroup/cpu ]; then + local share + + share=${rc_cgroup_cpu_shares:-$RC_CGROUP_CPU_SHARES} + if [ -n "$share" ]; then + cgroup_prepare "cpu" + cgroup_set_value "cpu.shares" $share + cgroup_add_process + fi + fi + return 0 +} diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in index f953afb..c9a3745 100644 --- a/sh/runscript.sh.in +++ b/sh/runscript.sh.in @@ -34,6 +34,7 @@ sourcex() sourcex "@LIBEXECDIR@/sh/functions.sh" sourcex "@LIBEXECDIR@/sh/rc-functions.sh" +[ "$RC_SYS" != "PREFIX" ] && sourcex -e "@LIBEXECDIR@/sh/rc-cgroup.sh" # Support LiveCD foo if sourcex -e "/sbin/livecd-functions.sh"; then @@ -204,30 +205,13 @@ unset _conf_d # Load any system overrides sourcex -e "@SYSCONFDIR@/rc.conf" -if [ "$RC_UNAME" = "Linux" -a "$RC_SYS" != "PREFIX" -a "$1" = "start" ]; then - openrc_cgroup=/sys/fs/cgroup/openrc - if [ -d ${openrc_cgroup} ]; then - cgroup=${openrc_cgroup}/${RC_SVCNAME} - mkdir -p ${cgroup} - [ -f "${cgroup}"/tasks ] && echo 0 > "${cgroup}"/tasks - fi - - shares="${rc_cgroup_cpu_shares:-$RC_CGROUP_CPU_SHARES}" - if [ -n "${shares}" -a -d /sys/fs/cgroup/cpu ]; then - cgroup=/sys/fs/cgroup/cpu/openrc_${RC_SVCNAME} - if [ ! -d ${cgroup} ]; then - mkdir -p ${cgroup} - fi - [ -f "${cgroup}"/cpu.shares ] && echo ${shares} > "${cgroup}"/cpu.shares - [ -f "${cgroup}"/tasks ] && echo 0 >> "${cgroup}"/tasks - fi - - #todo: add processes to cgroups based on settings in conf.d -fi - # Apply any ulimit defined [ -n "${rc_ulimit:-$RC_ULIMIT}" ] && ulimit ${rc_ulimit:-$RC_ULIMIT} +# Apply cgroups settings if defined +[ "$(command -v cgroup_set_limits)" = "cgroup_set_limits" ] && \ + cgroup_set_limits + # Load our script sourcex "$RC_SERVICE"