* [gentoo-commits] proj/openrc:master commit in: sh/, etc/
@ 2011-11-17 22:36 William Hubbs
0 siblings, 0 replies; 10+ messages in thread
From: William Hubbs @ 2011-11-17 22:36 UTC (permalink / raw
To: gentoo-commits
commit: 20df56f0b2a01bd2f8a70b8fb3fbd051c1aab8d8
Author: Patrick Lauer <patrick <AT> gentoo <DOT> org>
AuthorDate: Sat Nov 12 21:19:55 2011 +0000
Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Thu Nov 17 22:22:59 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=20df56f0
Add CGroup support
X-Gentoo-Bug: 390297
X-Gentoo-Bug: http://bugs.gentoo.org/show_bug.cgi?id=390297
---
etc/rc.conf.Linux | 7 +++++++
sh/runscript.sh.in | 22 ++++++++++++++++++++++
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/etc/rc.conf.Linux b/etc/rc.conf.Linux
index 9b5859a..585da3c 100644
--- a/etc/rc.conf.Linux
+++ b/etc/rc.conf.Linux
@@ -1,3 +1,10 @@
+# Set the control group for this service.
+# If you do not set this, the default setting is the value of
+# RC_SVCNAME.
+# This setting is ignored if you do not have CONFIG_CGROUPS active in
+# your kernel.
+# RC_CGROUP="foo"
+
##############################################################################
# LINUX SPECIFIC OPTIONS
diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index f86a510..73b4a59 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -189,6 +189,16 @@ fi
# Load any system overrides
sourcex -e "@SYSCONFDIR@/rc.conf"
+# Attach to CGroup - dir existing is enough for us
+if [ -d /sys/fs/cgroup/ ]; then
+ # use RC_SVCNAME unless overridden in conf.d
+ SVC_CGROUP=${RC_CGROUP:-$RC_SVCNAME}
+ mkdir -p /sys/fs/cgroup/${SVC_CGROUP}
+ # now attach self to cgroup - any children of this process will inherit this
+ echo $$ > /sys/fs/cgroup/${SVC_CGROUP}/tasks
+ # TODO: set res limits from conf.d
+fi
+
# Apply any ulimit defined
[ -n "${rc_ulimit:-$RC_ULIMIT}" ] && ulimit ${rc_ulimit:-$RC_ULIMIT}
@@ -291,3 +301,15 @@ while [ -n "$1" ]; do
eerror "$RC_SVCNAME: unknown function \`$1'"
exit 1
done
+
+# CGroup cleanup
+if [ -d /sys/fs/cgroup/ ]; then
+ # use RC_SVCNAME unless overridden in conf.d
+ SVC_CGROUP=${RC_CGROUP:-$RC_SVCNAME}
+ # reattach to root cgroup
+ echo $$ > /sys/fs/cgroup/tasks
+ # remove cgroup if empty, will fail if any task attached
+ rmdir /sys/fs/cgroup/${SVC_CGROUP} 2>/dev/null
+fi
+
+exit 0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/openrc:master commit in: sh/, etc/
@ 2011-11-17 22:46 William Hubbs
0 siblings, 0 replies; 10+ messages in thread
From: William Hubbs @ 2011-11-17 22:46 UTC (permalink / raw
To: gentoo-commits
commit: 0bbb764f70dcbaa8cfa3ffbb2b318274d1180120
Author: William Hubbs <williamh <AT> gentoo <DOT> org>
AuthorDate: Thu Nov 17 22:42:03 2011 +0000
Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Thu Nov 17 22:42:03 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=0bbb764f
Change RC_CGROUP to lower case
---
etc/rc.conf.Linux | 2 +-
sh/runscript.sh.in | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/etc/rc.conf.Linux b/etc/rc.conf.Linux
index 585da3c..963fc68 100644
--- a/etc/rc.conf.Linux
+++ b/etc/rc.conf.Linux
@@ -3,7 +3,7 @@
# RC_SVCNAME.
# This setting is ignored if you do not have CONFIG_CGROUPS active in
# your kernel.
-# RC_CGROUP="foo"
+# rc_cgroup="foo"
##############################################################################
# LINUX SPECIFIC OPTIONS
diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index 73b4a59..ca9c133 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -192,7 +192,7 @@ sourcex -e "@SYSCONFDIR@/rc.conf"
# Attach to CGroup - dir existing is enough for us
if [ -d /sys/fs/cgroup/ ]; then
# use RC_SVCNAME unless overridden in conf.d
- SVC_CGROUP=${RC_CGROUP:-$RC_SVCNAME}
+ SVC_CGROUP=${rc_cgroup:-$RC_SVCNAME}
mkdir -p /sys/fs/cgroup/${SVC_CGROUP}
# now attach self to cgroup - any children of this process will inherit this
echo $$ > /sys/fs/cgroup/${SVC_CGROUP}/tasks
@@ -305,7 +305,7 @@ done
# CGroup cleanup
if [ -d /sys/fs/cgroup/ ]; then
# use RC_SVCNAME unless overridden in conf.d
- SVC_CGROUP=${RC_CGROUP:-$RC_SVCNAME}
+ SVC_CGROUP=${rc_cgroup:-$RC_SVCNAME}
# reattach to root cgroup
echo $$ > /sys/fs/cgroup/tasks
# remove cgroup if empty, will fail if any task attached
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/openrc:master commit in: sh/, etc/
@ 2012-11-12 17:00 William Hubbs
0 siblings, 0 replies; 10+ messages in thread
From: William Hubbs @ 2012-11-12 17:00 UTC (permalink / raw
To: gentoo-commits
commit: 4f19c2f512d9a08599b6bdf1129f508fc9a4e055
Author: Alexander Vershilov <alexander.vershilov <AT> gmail <DOT> com>
AuthorDate: Fri Oct 26 05:05:41 2012 +0000
Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Mon Nov 12 16:58:00 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=4f19c2f5
Support cpu usage management for Linux
This commit was modified by William Hubbs as follows:
- The paths in the cgroup fs were put into variables to ease
maintenance.
- Documentation was added to rc.conf.Linux.
- The services were added originally to openrc/svcname cgroups under the
controller cgroups, but this left an "openrc" cgroup which was unused.
Now they are added to individual cgroups with the name openrc_${RC_SVCNAME}.
---
etc/rc.conf.Linux | 17 ++++++++++++++---
sh/runscript.sh.in | 21 +++++++++++++++++----
2 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/etc/rc.conf.Linux b/etc/rc.conf.Linux
index 909e6a9..6285bde 100644
--- a/etc/rc.conf.Linux
+++ b/etc/rc.conf.Linux
@@ -20,10 +20,21 @@
# consolefont, numlock, etc ...)
rc_tty_number=12
+##############################################################################
+# CGROUPS RESOURCE MANAGEMENT
+
# If you have cgroups turned on in your kernel, this switch controls
# whether or not a group for each controler is mounted under
# /sys/fs/cgroup.
-# Support for process management by cgroups is planned in the future,
-# so if you turn this off, be aware that you may not be able to use that
-# feature.
+# None of the other options in this section work if this is set to "NO".
#rc_controller_cgroups="YES"
+
+# These options can be set globally in this file; however, if you do
+# this, the same setting will apply to all of your services.
+# If you want different settings for each service, place the settings in
+# /etc/conf.d/foo for service foo.
+
+# This is the number of CPU shares a service is allowed to use. The
+# default value, set by the kernel, is 1024.
+# Also, this setting is not preserved if you suspend your computer.
+#rc_cgroup_cpu_shares=1024
diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in
index d53d70d..21ff39a 100644
--- a/sh/runscript.sh.in
+++ b/sh/runscript.sh.in
@@ -193,11 +193,24 @@ unset _conf_d
# Load any system overrides
sourcex -e "@SYSCONFDIR@/rc.conf"
-if [ "$RC_UNAME" = "Linux" -a "$1" = "start" ]; then
- if [ -d /sys/fs/cgroup/openrc ]; then
- mkdir -p /sys/fs/cgroup/openrc/${RC_SVCNAME}
- echo $$ > /sys/fs/cgroup/openrc/${RC_SVCNAME}/tasks
+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
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/openrc:master commit in: sh/, etc/
@ 2013-02-19 23:11 William Hubbs
0 siblings, 0 replies; 10+ messages in thread
From: William Hubbs @ 2013-02-19 23:11 UTC (permalink / raw
To: gentoo-commits
commit: fac96b4df4b61db399bfa18549be162e9861b0b5
Author: William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Sun Feb 17 21:14:06 2013 +0000
Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Tue Feb 19 23:09:30 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=fac96b4d
cgroups: major update to cgroups support
This reworks cgroups support so we have one variable in rc.conf for each
controller instead of each setting.
Also we add support for all of the possible cgroup controllers.
I would like to thank Alexander Vershilov for his help with testing and
reworking this code.
---
etc/rc.conf.Linux | 40 +++++++++++++++++++++----
sh/rc-cgroup.sh.in | 83 +++++++++++++++++++++++++++++++++++-----------------
2 files changed, 90 insertions(+), 33 deletions(-)
diff --git a/etc/rc.conf.Linux b/etc/rc.conf.Linux
index 7571f98..4fb48ae 100644
--- a/etc/rc.conf.Linux
+++ b/etc/rc.conf.Linux
@@ -29,12 +29,40 @@ rc_tty_number=12
# None of the other options in this section work if this is set to "NO".
#rc_controller_cgroups="YES"
-# These options can be set globally in this file; however, if you do
-# this, the same setting will apply to all of your services.
+# The following settings allow you to set up values for the cgroup
+# controllers for your services.
+# They can be set in this file;, however, if you do this, the settings
+# will apply to all of your services.
# If you want different settings for each service, place the settings in
# /etc/conf.d/foo for service foo.
+# The format is to specify the names of the settings followed by their
+# values. Each variable can hold multiple settings.
+# For example, you would use this to set the cpu.shares setting in the
+# cpu controller to 512 for your service.
+# rc_cgroup_cpu="
+# cpu.shares 512
+# "
+#
+#For more information about the adjustments that can be made with
+#cgroups, see Documentation/cgroups/* in the linux kernel source tree.
+
+# Set the blkio controller settings for this service.
+#rc_cgroup_blkio=""
+
+# Set the cpu controller settings for this service.
+#rc_cgroup_cpu=""
+
+# Add this service to the cpuacct controller (any value means yes).
+#rc_cgroup_cpuacct=""
+
+# Set the cpuset controller settings for this service.
+#rc_cgroup_cpuset=""
+
+# Set the devices controller settings for this service.
+#rc_cgroup_devices=""
+
+# Set the memory controller settings for this service.
+#rc_cgroup_memory=""
-# This is the number of CPU shares a service is allowed to use. The
-# default value, set by the kernel, is 1024.
-# This requires CONFIG_FAIR_GROUP_SCHED to be set in the kernel.
-#rc_cgroup_cpu_shares=1024
+# Set the net_prio controller settings for this service.
+#rc_cgroup_net_prio=""
diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index c9a0062..449c1d3 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -15,45 +15,74 @@ cgroup_find_path()
echo $result
}
-# prepare values to be attached inside cgroups
-cgroup_prepare()
+cgroup_set_values()
{
- local h=$(cgroup_find_path "$1")
+ [ -n "$1" -a -n "$2" -a -d "/sys/fs/cgroup/$1" ] || return 0
+
+ local controller="$1" h=$(cgroup_find_path "$1")
cgroup="/sys/fs/cgroup/${1}${h}openrc_${RC_SVCNAME}"
- [ -d ${cgroup} ] || mkdir -p ${cgroup}
- return 0
-}
+ [ -d "$cgroup" ] || mkdir -p "$cgroup"
-cgroup_set_value()
-{
- [ -f "$cgroup/${1}" -a -n "$2" ] && echo $2 > "${cgroup}/${1}"
- return 0
-}
+ set -- $2
+ local name val
+ while [ -n "$1" -a "$controller" != "cpuacct" ]; do
+ case "$1" in
+ $controller.*)
+ if [ -n "$name" -a -f "$cgroup/$name" -a -n "$val" ]; then
+ veinfo "$RC_SVCNAME: Setting $cgroup/$name to $val"
+ echo $val > "$cgroup/$name"
+ fi
+ name=$1
+ val=
+ ;;
+ *)
+ val="$val $1"
+ ;;
+ esac
+ shift
+ done
+ if [ -n "$name" -a -f "$cgroup/$name" -a -n "$val" ]; then
+ veinfo "$RC_SVCNAME: Setting $cgroup/$name to $val"
+ echo $val > "$cgroup/$name"
+ fi
+
+ if [ -f "$cgroup/tasks" ]; then
+ veinfo "$RC_SVCNAME: adding to $cgroup/tasks"
+ echo 0 > "$cgroup/tasks"
+ fi
-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
+ 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
+ local blkio="${rc_cgroup_blkio:-$RC_CGROUP_BLKIO}"
+ [ -n "$blkio" ] && cgroup_set_values blkio "$blkio"
+
+ local cpu="${rc_cgroup_cpu:-$RC_CGROUP_CPU}"
+ [ -n "$cpu" ] && cgroup_set_values cpu "$cpu"
+
+ local cpuacct="${rc_cgroup_cpuacct:-$RC_CGROUP_CPUACCT}"
+ [ -n "$cpuacct" ] && cgroup_set_values cpuacct "$cpuacct"
+
+ local cpuset="${rc_cgroup_cpuset:-$RC_CGROUP_cpuset}"
+ [ -n "$cpuset" ] && cgroup_set_values cpuset "$cpuset"
+
+ local devices="${rc_cgroup_devices:-$RC_CGROUP_DEVICES}"
+ [ -n "$devices" ] && cgroup_set_values devices "$devices"
+
+ local memory="${rc_cgroup_memory:-$RC_CGROUP_MEMORY}"
+ [ -n "$memory" ] && cgroup_set_values memory "$memory"
+
+ local net_prio="${rc_cgroup_net_prio:-$RC_CGROUP_NET_PRIO}"
+ [ -n "$net_prio" ] && cgroup_set_values net_prio "$net_prio"
- 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
}
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/openrc:master commit in: sh/, etc/
@ 2013-03-12 18:10 William Hubbs
0 siblings, 0 replies; 10+ messages in thread
From: William Hubbs @ 2013-03-12 18:10 UTC (permalink / raw
To: gentoo-commits
commit: 67944412247173c65b14e7eaeb20b961241e1bd5
Author: William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Sat Feb 16 18:53:31 2013 +0000
Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Tue Mar 12 17:57:44 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=67944412
Make fuser command time out
This avoids situations in which fuser hangs because of open files on
remote file systems when the remote system goes down.
I have also passed this bug on to the maintainers of psmisc since it
should really be fixed in fuser.
This is based on a patch submitted by evermind <AT> tuxfamily.org
Reported-by: evermind <AT> tuxfamily.org
X-Gentoo-Bug: 455458
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=455458
---
etc/rc.conf.Linux | 4 ++++
sh/rc-mount.sh | 3 ++-
2 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/etc/rc.conf.Linux b/etc/rc.conf.Linux
index 4fb48ae..d85b1c1 100644
--- a/etc/rc.conf.Linux
+++ b/etc/rc.conf.Linux
@@ -20,6 +20,10 @@
# consolefont, numlock, etc ...)
rc_tty_number=12
+# This is how long fuser should wait for a remote server to respond. The
+# default is 60 seconds, but it can be adjusted here.
+#rc_fuser_timeout=60
+
##############################################################################
# CGROUPS RESOURCE MANAGEMENT
diff --git a/sh/rc-mount.sh b/sh/rc-mount.sh
index 2bb1450..454f9f9 100644
--- a/sh/rc-mount.sh
+++ b/sh/rc-mount.sh
@@ -41,7 +41,8 @@ do_unmount()
retry=4 # Effectively TERM, sleep 1, TERM, sleep 1, KILL, sleep 1
while ! LC_ALL=C $cmd "$mnt" 2>/dev/null; do
if type fuser >/dev/null 2>&1; then
- pids="$(fuser $f_opts "$mnt" 2>/dev/null)"
+ pids="$(timeout -k 10 -s KILL "${rc_fuser_timeout:-60}" \
+ fuser $f_opts "$mnt" 2>/dev/null)"
fi
case " $pids " in
*" $$ "*)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/openrc:master commit in: sh/, etc/
@ 2013-04-25 22:02 William Hubbs
0 siblings, 0 replies; 10+ messages in thread
From: William Hubbs @ 2013-04-25 22:02 UTC (permalink / raw
To: gentoo-commits
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
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/openrc:master commit in: sh/, etc/
@ 2015-05-08 17:11 William Hubbs
0 siblings, 0 replies; 10+ messages in thread
From: William Hubbs @ 2015-05-08 17:11 UTC (permalink / raw
To: gentoo-commits
commit: abef2fcb2dbcc277bb05f0d9c674d4b47826f17f
Author: William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Fri May 8 16:29:49 2015 +0000
Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Fri May 8 16:39:39 2015 +0000
URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=abef2fcb
Make the default start, stop and status functions overridable
This will make it possible to add support for supervision suites such as
runit and s6.
etc/rc.conf.in | 6 ++++
sh/Makefile | 2 +-
sh/openrc-run.sh.in | 75 ++++++-------------------------------------------
sh/start-stop-daemon.sh | 71 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 87 insertions(+), 67 deletions(-)
diff --git a/etc/rc.conf.in b/etc/rc.conf.in
index 69a5cf2..b16aaff 100644
--- a/etc/rc.conf.in
+++ b/etc/rc.conf.in
@@ -77,6 +77,12 @@
#rc_crashed_stop=NO
#rc_crashed_start=YES
+# Set rc_supervisor to use a program to monitor your daemons and restart
+# them when they crash.
+# Leaving this undefined uses start-stop-daemon, which is OpenRC's
+# default.
+#rc_supervisor=""
+
# Set rc_nocolor to yes if you do not want colors displayed in OpenRC
# output.
#rc_nocolor=NO
diff --git a/sh/Makefile b/sh/Makefile
index ee9d74d..3f8881e 100644
--- a/sh/Makefile
+++ b/sh/Makefile
@@ -1,7 +1,7 @@
DIR= ${LIBEXECDIR}/sh
SRCS= init.sh.in functions.sh.in gendepends.sh.in \
openrc-run.sh.in rc-functions.sh.in tmpfiles.sh.in ${SRCS-${OS}}
-INC= rc-mount.sh functions.sh rc-functions.sh
+INC= rc-mount.sh functions.sh rc-functions.sh start-stop-daemon.sh
BIN= gendepends.sh init.sh openrc-run.sh tmpfiles.sh ${BIN-${OS}}
INSTALLAFTER= _installafter
diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in
index e279f11..4d286b2 100644
--- a/sh/openrc-run.sh.in
+++ b/sh/openrc-run.sh.in
@@ -125,72 +125,6 @@ _status()
fi
}
-# Template start / stop / status functions
-start()
-{
- [ -n "$command" ] || return 0
- local _background=
- ebegin "Starting ${name:-$RC_SVCNAME}"
- if yesno "${command_background}"; then
- if [ -z "${pidfile}" ]; then
- eend 1 "command_background option used but no pidfile specified"
- return 1
- fi
- _background="--background --make-pidfile"
- fi
- if yesno "$start_inactive"; then
- local _inactive=false
- service_inactive && _inactive=true
- mark_service_inactive
- fi
- eval start-stop-daemon --start \
- --exec $command \
- ${chroot:+--chroot} $chroot \
- ${procname:+--name} $procname \
- ${pidfile:+--pidfile} $pidfile \
- $_background $start_stop_daemon_args \
- -- $command_args
- if eend $? "Failed to start $RC_SVCNAME"; then
- service_set_value "command" "${command}"
- [ -n "${chroot}" ] && service_set_value "chroot" "${chroot}"
- [ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
- [ -n "${procname}" ] && service_set_value "procname" "${procname}"
- return 0
- fi
- if yesno "$start_inactive"; then
- if ! $_inactive; then
- mark_service_stopped
- fi
- fi
- return 1
-}
-
-stop()
-{
- local startcommand="$(service_get_value "command")"
- local startchroot="$(service_get_value "chroot")"
- local startpidfile="$(service_get_value "pidfile")"
- local startprocname="$(service_get_value "procname")"
- command="${startcommand:-$command}"
- chroot="${startchroot:-$chroot}"
- pidfile="${startpidfile:-$pidfile}"
- procname="${startprocname:-$procname}"
- [ -n "$command" -o -n "$procname" -o -n "$pidfile" ] || return 0
- ebegin "Stopping ${name:-$RC_SVCNAME}"
- start-stop-daemon --stop \
- ${retry:+--retry} $retry \
- ${command:+--exec} $command \
- ${procname:+--name} $procname \
- ${pidfile:+--pidfile} $chroot$pidfile \
- ${stopsig:+--signal} $stopsig
- eend $? "Failed to stop $RC_SVCNAME"
-}
-
-status()
-{
- _status
-}
-
yesno $RC_DEBUG && set -x
_conf_d=${RC_SERVICE%/*}/../conf.d
@@ -212,6 +146,15 @@ unset _conf_d
# Load any system overrides
sourcex -e "@SYSCONFDIR@/rc.conf"
+# load a service supervisor
+sourcex "@LIBEXECDIR@/sh/start-stop-daemon.sh"
+if [ -n "$rc_supervisor" ]; then
+ if ! sourcex -e "@LIBEXECDIR@/sh/${rc_supervisor}.sh"; then
+ ewarn "$rc_supervisor is an invalid value for rc_supervisor"
+ ewarn "Using the default."
+ fi
+fi
+
# Set verbose mode
if yesno "${rc_verbose:-$RC_VERBOSE}"; then
EINFO_VERBOSE=yes
diff --git a/sh/start-stop-daemon.sh b/sh/start-stop-daemon.sh
new file mode 100644
index 0000000..aae6792
--- /dev/null
+++ b/sh/start-stop-daemon.sh
@@ -0,0 +1,71 @@
+# Default start / stop / status functions
+# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
+# Released under the 2-clause BSD license.
+
+start()
+{
+ [ -n "$command" ] || return 0
+
+ local _background=
+ ebegin "Starting ${name:-$RC_SVCNAME}"
+ if yesno "${command_background}"; then
+ if [ -z "${pidfile}" ]; then
+ eend 1 "command_background option used but no pidfile specified"
+ return 1
+ fi
+ if [ -n "${command_args_background}" ]; then
+ eend 1 "command_background used with command_args_background"
+ return 1
+ fi
+ _background="--background --make-pidfile"
+ fi
+ if yesno "$start_inactive"; then
+ local _inactive=false
+ service_inactive && _inactive=true
+ mark_service_inactive
+ fi
+ eval start-stop-daemon --start \
+ --exec $command \
+ ${procname:+--name} $procname \
+ ${pidfile:+--pidfile} $pidfile \
+ ${command_user+--user} $command_user \
+ $_background $start_stop_daemon_args \
+ -- $command_args $command_args_background
+ if eend $? "Failed to start $RC_SVCNAME"; then
+ service_set_value "command" "${command}"
+ [ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
+ [ -n "${procname}" ] && service_set_value "procname" "${procname}"
+ return 0
+ fi
+ if yesno "$start_inactive"; then
+ if ! $_inactive; then
+ mark_service_stopped
+ fi
+ fi
+ return 1
+}
+
+stop()
+{
+ local startcommand="$(service_get_value "command")"
+ local startpidfile="$(service_get_value "pidfile")"
+ local startprocname="$(service_get_value "procname")"
+ command="${startcommand:-$command}"
+ pidfile="${startpidfile:-$pidfile}"
+ procname="${startprocname:-$procname}"
+ [ -n "$command" -o -n "$procname" -o -n "$pidfile" ] || return 0
+ ebegin "Stopping ${name:-$RC_SVCNAME}"
+ start-stop-daemon --stop \
+ ${retry:+--retry} $retry \
+ ${command:+--exec} $command \
+ ${procname:+--name} $procname \
+ ${pidfile:+--pidfile} $pidfile \
+ ${stopsig:+--signal} $stopsig
+
+ eend $? "Failed to stop $RC_SVCNAME"
+}
+
+status()
+{
+ _status
+}
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/openrc:master commit in: sh/, etc/
@ 2015-10-06 21:34 William Hubbs
0 siblings, 0 replies; 10+ messages in thread
From: William Hubbs @ 2015-10-06 21:34 UTC (permalink / raw
To: gentoo-commits
commit: 80d3928b0d13f09a9c1e82bd27c9fff943d84d43
Author: Austin S. Hemmelgarn <ahferroin7 <AT> gmail <DOT> com>
AuthorDate: Tue Oct 6 20:02:28 2015 +0000
Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Tue Oct 6 20:05:35 2015 +0000
URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=80d3928b
cgroups: Add the hugetlb, net_cls and pids controllers
Note from WilliamH: I slightly rearranged the code and added the
settings in rc.conf.
X-Gentoo-Bug: 555488
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=555488
etc/rc.conf.Linux | 9 +++++++++
sh/rc-cgroup.sh.in | 9 +++++++++
2 files changed, 18 insertions(+)
diff --git a/etc/rc.conf.Linux b/etc/rc.conf.Linux
index a8ad58b..f04f96e 100644
--- a/etc/rc.conf.Linux
+++ b/etc/rc.conf.Linux
@@ -62,12 +62,21 @@ rc_tty_number=12
# Set the devices controller settings for this service.
#rc_cgroup_devices=""
+# Set the hugetlb controller settings for this service.
+#rc_cgroup_hugetlb=""
+
# Set the memory controller settings for this service.
#rc_cgroup_memory=""
+# Set the net_cls controller settings for this service.
+#rc_cgroup_net_cls=""
+
# Set the net_prio controller settings for this service.
#rc_cgroup_net_prio=""
+# Set the pids controller settings for this service.
+#rc_cgroup_pids=""
+
# 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
diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index 3f34d17..b49c711 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -109,12 +109,21 @@ cgroup_set_limits()
local devices="${rc_cgroup_devices:-$RC_CGROUP_DEVICES}"
[ -n "$devices" ] && cgroup_set_values devices "$devices"
+ local hugetlb="${rc_cgroup_hugetlb:-$RC_CGROUP_HUGETLB}"
+ [ -n "$hugetlb" ] && cgroup_set_values hugetlb "$hugetlb"
+
local memory="${rc_cgroup_memory:-$RC_CGROUP_MEMORY}"
[ -n "$memory" ] && cgroup_set_values memory "$memory"
+ local net_cls="${rc_cgroup_net_cls:-$RC_CGROUP_NET_CLS}"
+ [ -n "$net_cls" ] && cgroup_set_values net_cls "$net_cls"
+
local net_prio="${rc_cgroup_net_prio:-$RC_CGROUP_NET_PRIO}"
[ -n "$net_prio" ] && cgroup_set_values net_prio "$net_prio"
+ local pids="${rc_cgroup_pids:-$RC_CGROUP_PIDS}"
+ [ -n "$pids" ] && cgroup_set_values pids "$pids"
+
return 0
}
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/openrc:master commit in: sh/, etc/
@ 2016-12-17 22:57 William Hubbs
0 siblings, 0 replies; 10+ messages in thread
From: William Hubbs @ 2016-12-17 22:57 UTC (permalink / raw
To: gentoo-commits
commit: 8ad460c54ce66aa0900cf872d9ebfacf0c03f9da
Author: Doug Freed <dwfreed <AT> mtu <DOT> edu>
AuthorDate: Sat Dec 17 18:41:02 2016 +0000
Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Sat Dec 17 18:41:02 2016 +0000
URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=8ad460c5
Fix typos
Fixes #99
etc/rc.shutdown.in | 2 +-
sh/init.sh.Linux.in | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/etc/rc.shutdown.in b/etc/rc.shutdown.in
index b85a962..de3e09b 100644
--- a/etc/rc.shutdown.in
+++ b/etc/rc.shutdown.in
@@ -14,7 +14,7 @@ trap : SIGINT SIGQUIT
# Try and use stuff in /lib over anywhere else so we can shutdown
# local mounts correctly.
-LD_LIBRARY_PATH="/lib${LD_LIBRARY_PATH:+:}${LDLIBRARY_PATH}" ; export LD_LIBRARY_PATH
+LD_LIBRARY_PATH="/lib${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}" ; export LD_LIBRARY_PATH
# If $TERM is not set then assume default of @TERM@
# This gives us a nice colour boot :)
diff --git a/sh/init.sh.Linux.in b/sh/init.sh.Linux.in
index 7645775..fcae0d2 100644
--- a/sh/init.sh.Linux.in
+++ b/sh/init.sh.Linux.in
@@ -32,7 +32,7 @@ unset f
if $mountproc; then
procfs="proc"
- [ "$RC_UNAME" = "GNU/kFreeBSD" ] && proc="linprocfs"
+ [ "$RC_UNAME" = "GNU/kFreeBSD" ] && procfs="linprocfs"
ebegin "Mounting /proc"
if ! fstabinfo --mount /proc; then
mount -n -t "$procfs" -o noexec,nosuid,nodev proc /proc
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [gentoo-commits] proj/openrc:master commit in: sh/, etc/
@ 2017-09-15 18:31 William Hubbs
0 siblings, 0 replies; 10+ messages in thread
From: William Hubbs @ 2017-09-15 18:31 UTC (permalink / raw
To: gentoo-commits
commit: 6a5ca2ab368d0a85f51bb559672dba2e3ffcc6be
Author: William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
AuthorDate: Thu Sep 14 16:40:26 2017 +0000
Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Thu Sep 14 21:17:20 2017 +0000
URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=6a5ca2ab
make the procedure for killing child processes of services configurable
etc/rc.conf | 29 ++++++++++++++++++++++++++---
sh/rc-cgroup.sh.in | 13 ++++++++-----
2 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/etc/rc.conf b/etc/rc.conf
index d9ad911d..b7296d35 100644
--- a/etc/rc.conf
+++ b/etc/rc.conf
@@ -277,10 +277,33 @@ rc_tty_number=12
# Set this to YES if you 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>.
+# Be aware that setting this to yes means all of a service's
+# child processes will be killed. Keep this in mind if you set this to
+# yes here instead of for the individual services 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.
+# The process followed in this cleanup is the following:
+# 1. send stopsig (sigterm if it isn't set) to all processes left in the
+# cgroup immediately followed by sigcont.
+# 2. Send sighup to all processes in the cgroup if rc_send_sighup is
+# yes.
+# 3. delay for rc_timeout_stopsec seconds.
+# 4. send sigkill to all processes in the cgroup unless disabled by
+# setting rc_send_sigkill to no.
# rc_cgroup_cleanup="NO"
+
+# If this is yes, we will send sighup to the processes in the cgroup
+# immediately after stopsig and sigcont.
+#rc_send_sighup="NO"
+
+# This is the amount of time in seconds that we delay after sending sigcont
+# and optionally sighup, before we optionally send sigkill to all
+# processes in the # cgroup.
+# The default is 90 seconds.
+#rc_timeout_stopsec="90"
+
+# If this is set to no, we do not send sigkill to all processes in the
+# cgroup.
+#rc_send_sigkill="YES"
diff --git a/sh/rc-cgroup.sh.in b/sh/rc-cgroup.sh.in
index 47a007b6..4b713594 100644
--- a/sh/rc-cgroup.sh.in
+++ b/sh/rc-cgroup.sh.in
@@ -204,10 +204,13 @@ cgroup_cleanup()
local pids
pids="$(cgroup_get_pids)"
if [ -n "${pids}" ]; then
- kill -s TERM "${pids}"
- sleep 1
- pids="$(cgroup_get_pids)"
- [ -n "${pids}" ] &&
- kill -s KILL "${pids}"
+ kill -s "${stopsig:-SIGTERM}" ${pids} 2> /dev/null
+ kill -s SIGCONT ${pids} 2> /dev/null
+ yesno "${rc_send_sighup:-no}" &&
+ kill -s SIGHUP ${pids} 2> /dev/null
+ sleep "${rc_timeout_stopsec:-90}"
+ yesno "${rc_send_sigkill:-yes}" &&
+ kill -s SIGKILL ${pids} 2> /dev/null
fi
+ eend 0
}
^ permalink raw reply related [flat|nested] 10+ messages in thread
end of thread, other threads:[~2017-09-15 18:31 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-06 21:34 [gentoo-commits] proj/openrc:master commit in: sh/, etc/ William Hubbs
-- strict thread matches above, loose matches on Subject: below --
2017-09-15 18:31 William Hubbs
2016-12-17 22:57 William Hubbs
2015-05-08 17:11 William Hubbs
2013-04-25 22:02 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox