From: "William Hubbs" <williamh@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/openrc:master commit in: sh/, etc/
Date: Thu, 25 Apr 2013 22:02:04 +0000 (UTC) [thread overview]
Message-ID: <1366927159.c984506537fbb8a3adefd2d57dd4dc831eeb79c3.WilliamH@OpenRC> (raw)
commit: c984506537fbb8a3adefd2d57dd4dc831eeb79c3
Author: Alexander Vershilov <alexander.vershilov <AT> gmail <DOT> com>
AuthorDate: Tue Apr 16 05:52:33 2013 +0000
Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Thu Apr 25 21:59:19 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=c9845065
add cgroup cleanup support
This adds the ability to kill all processes within a service's cgroup
when that service is stopped or restarted.
---
etc/rc.conf.Linux | 10 ++++++++++
sh/rc-cgroup.sh.in | 35 +++++++++++++++++++++++++++++++++++
sh/runscript.sh.in | 2 ++
3 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/etc/rc.conf.Linux b/etc/rc.conf.Linux
index 4fb48ae..79bd971 100644
--- a/etc/rc.conf.Linux
+++ b/etc/rc.conf.Linux
@@ -66,3 +66,13 @@ rc_tty_number=12
# Set the net_prio controller settings for this service.
#rc_cgroup_net_prio=""
+
+# Set this to YES if yu want all of the processes in a service's cgroup
+# killed when the service is stopped or restarted.
+# This should not be set globally because it kills all of the service's
+# child processes, and most of the time this is undesirable. Please set
+# it in /etc/conf.d/<service>.
+# To perform this cleanup manually for a stopped service, you can
+# execute cgroup_cleanup with /etc/init.d/<service> cgroup_cleanup or
+# rc-service <service> cgroup_cleanup.
+# rc_cgroup_cleanup="NO"
diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index 449c1d3..c057fc8 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -1,6 +1,7 @@
#!@SHELL@
# Copyright (c) 2012 Alexander Vershilov <qnikst@gentoo.org>
# Released under the 2-clause BSD license.
+extra_stopped_commands="${extra_stopped_commands} cgroup_cleanup"
cgroup_find_path()
{
@@ -15,6 +16,21 @@ cgroup_find_path()
echo $result
}
+cgroup_get_pids()
+{
+ local p
+ pids=
+ while read p; do
+ [ $p -eq $$ ] || $pids="${pids} ${p}"
+ done < /sys/fs/cgroup/openrc/${RC_SVCNAME}/tasks
+ [ -n "$pids" ]
+}
+
+cgroup_running()
+{
+ [ -d "/sys/fs/cgroup/openrc/${RC_SVCNAME}" ]
+}
+
cgroup_set_values()
{
[ -n "$1" -a -n "$2" -a -d "/sys/fs/cgroup/$1" ] || return 0
@@ -86,3 +102,22 @@ cgroup_set_limits()
return 0
}
+
+cgroup_cleanup()
+{
+ yesno "${rc_cgroup_cleanup:-no}" && cgroup_running || return 0
+ ebegin "starting cgroups cleanup"
+ for sig in TERM QUIT INT; do
+ cgroup_get_pids || { eend 0 "finished" ; return 0 ; }
+ for i in 0 1; do
+ kill -s $sig $pids
+ for j in 0 1 2; do
+ cgroup_get_pids || { eend 0 "finished" ; return 0 ; }
+ sleep 1
+ done
+ done
+ done
+ cgroup_get_pids || { eend 0 "finished" ; return 0; }
+ kill -9 $pids
+ eend $(cgroup_running && echo 1 || echo 0) "fail to stop all processes"
+}
diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index c9a3745..dcddd9b 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -302,6 +302,8 @@ while [ -n "$1" ]; do
then
"$1"_post || exit $?
fi
+ [ "$(command -v cgroup_cleanup)" = "cgroup_cleanup" ] && \
+ cgroup_cleanup
shift
continue 2
else
next reply other threads:[~2013-04-25 22:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-25 22:02 William Hubbs [this message]
-- strict thread matches above, loose matches on Subject: below --
2017-09-15 18:31 [gentoo-commits] proj/openrc:master commit in: sh/, etc/ William Hubbs
2016-12-17 22:57 William Hubbs
2015-10-06 21:34 William Hubbs
2015-05-08 17:11 William Hubbs
2013-03-12 18:10 William Hubbs
2013-02-19 23:11 William Hubbs
2012-11-12 17:00 William Hubbs
2011-11-17 22:46 William Hubbs
2011-11-17 22:36 William Hubbs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1366927159.c984506537fbb8a3adefd2d57dd4dc831eeb79c3.WilliamH@OpenRC \
--to=williamh@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox