rc: add support for cpuset(1)
If ${name}_cpuset is specified (and /usr is mounted), cpuset(1) will be run to limit the service to the configured cpuset. PR: 142434 Reviewed by: kevans
This commit is contained in:
parent
062a7b918f
commit
0661f93892
@ -52,6 +52,8 @@ ID="/usr/bin/id"
|
|||||||
IDCMD="if [ -x $ID ]; then $ID -un; fi"
|
IDCMD="if [ -x $ID ]; then $ID -un; fi"
|
||||||
PS="/bin/ps -ww"
|
PS="/bin/ps -ww"
|
||||||
JID=0
|
JID=0
|
||||||
|
CPUSET="/usr/bin/cpuset"
|
||||||
|
|
||||||
# rc_service provides the path to the service script that we are executing.
|
# rc_service provides the path to the service script that we are executing.
|
||||||
# This is not being set here in an execution context, necessarily, so it's
|
# This is not being set here in an execution context, necessarily, so it's
|
||||||
# really just a reasonable guess, and it will get overwritten later if
|
# really just a reasonable guess, and it will get overwritten later if
|
||||||
@ -777,6 +779,9 @@ startmsg()
|
|||||||
# ${name}_chdir n Directory to cd to before running ${command}
|
# ${name}_chdir n Directory to cd to before running ${command}
|
||||||
# (if not using ${name}_chroot).
|
# (if not using ${name}_chroot).
|
||||||
#
|
#
|
||||||
|
# ${name}_cpuset n A list of CPUs to run ${command} on.
|
||||||
|
# Requires /usr to be mounted.
|
||||||
|
#
|
||||||
# ${name}_flags n Arguments to call ${command} with.
|
# ${name}_flags n Arguments to call ${command} with.
|
||||||
# NOTE: $flags from the parent environment
|
# NOTE: $flags from the parent environment
|
||||||
# can be used to override this.
|
# can be used to override this.
|
||||||
@ -963,6 +968,23 @@ run_rc_command()
|
|||||||
_pidcmd=
|
_pidcmd=
|
||||||
_procname=${procname:-${command}}
|
_procname=${procname:-${command}}
|
||||||
|
|
||||||
|
eval _cpuset=\$${name}_cpuset
|
||||||
|
|
||||||
|
# Loose validation of the configured cpuset; just make sure it starts
|
||||||
|
# with a number. There have also been cases in the past where a hyphen
|
||||||
|
# in a service name has caused eval errors, which trickle down into
|
||||||
|
# various variables; don't let a situation like that break a bunch of
|
||||||
|
# services just because of cpuset(1).
|
||||||
|
case "$_cpuset" in
|
||||||
|
[0-9]*) ;;
|
||||||
|
*) _cpuset="" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
_cpusetcmd=
|
||||||
|
if [ -n "$_cpuset" -a -x $CPUSET ]; then
|
||||||
|
_cpusetcmd="$CPUSET -l $_cpuset"
|
||||||
|
fi
|
||||||
|
|
||||||
# setup pid check command
|
# setup pid check command
|
||||||
if [ -n "$_procname" ]; then
|
if [ -n "$_procname" ]; then
|
||||||
if [ -n "$pidfile" ]; then
|
if [ -n "$pidfile" ]; then
|
||||||
@ -1059,7 +1081,7 @@ run_rc_command()
|
|||||||
eval "export -- $_env"
|
eval "export -- $_env"
|
||||||
fi
|
fi
|
||||||
_run_rc_precmd || return 1
|
_run_rc_precmd || return 1
|
||||||
_run_rc_doit "$_cmd $rc_extra_args" || return 1
|
_run_rc_doit "$_cpusetcmd $_cmd $rc_extra_args" || return 1
|
||||||
_run_rc_postcmd
|
_run_rc_postcmd
|
||||||
return $_return
|
return $_return
|
||||||
fi
|
fi
|
||||||
@ -1105,6 +1127,11 @@ run_rc_command()
|
|||||||
_run_rc_precmd || return 1
|
_run_rc_precmd || return 1
|
||||||
if [ -n "$rc_pid" ]; then
|
if [ -n "$rc_pid" ]; then
|
||||||
echo "${name} is running as pid $rc_pid."
|
echo "${name} is running as pid $rc_pid."
|
||||||
|
# for cpuset debug only, not committable (cut)
|
||||||
|
if [ -n "$_cpuset" -a -x $CPUSET ]; then
|
||||||
|
echo -n "on CPU(s)"
|
||||||
|
$CPUSET -g -p "$rc_pid" | cut -s -d: -f 2
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "${name} is not running."
|
echo "${name} is not running."
|
||||||
return 1
|
return 1
|
||||||
@ -1130,6 +1157,7 @@ run_rc_command()
|
|||||||
_cd=
|
_cd=
|
||||||
_doit="\
|
_doit="\
|
||||||
${_nice:+nice -n $_nice }\
|
${_nice:+nice -n $_nice }\
|
||||||
|
$_cpusetcmd \
|
||||||
${_fib:+setfib -F $_fib }\
|
${_fib:+setfib -F $_fib }\
|
||||||
${_env:+env $_env }\
|
${_env:+env $_env }\
|
||||||
chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\
|
chroot ${_user:+-u $_user }${_group:+-g $_group }${_groups:+-G $_groups }\
|
||||||
@ -1139,7 +1167,7 @@ $_chroot $command $rc_flags $command_args"
|
|||||||
_doit="\
|
_doit="\
|
||||||
${_fib:+setfib -F $_fib }\
|
${_fib:+setfib -F $_fib }\
|
||||||
${_env:+env $_env }\
|
${_env:+env $_env }\
|
||||||
$command $rc_flags $command_args"
|
$_cpusetcmd $command $rc_flags $command_args"
|
||||||
if [ -n "$_user" ]; then
|
if [ -n "$_user" ]; then
|
||||||
_doit="su -m $_user -c 'sh -c \"$_doit\"'"
|
_doit="su -m $_user -c 'sh -c \"$_doit\"'"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user