On 2013-12-19 Thu 13:43 PM |, Craig R. Skinner wrote: > Enhance rc.d/rc.subr with lowered/raised daemon running priority. >
Take 2: Replace /etc/rc.d/<daemon> rc_renice=X with /etc/rc.conf.local <daemon>_nice=X $ fgrep _nice /etc/rc.conf.local sshd_nice=-10 dhcpd_nice=15 inetd_nice=YES greyscanner_nice=YES $ sudo /etc/rc.d/dhcpd -d restart doing rc_read_runfile doing rc_read_runfile doing rc_check dhcpd doing rc_stop doing rc_wait stop doing rc_check doing rc_rm_runfile (ok) doing rc_read_runfile doing rc_check dhcpd doing rc_pre doing rc_start doing rc_write_runfile doing rc_reprioritise 6142: old priority 0, new priority 15 (ok) $ ps -l -U _dhcp UID PID PPID CPU PRI NI VSZ RSS WCHAN STAT TT TIME COMMAND 77 6142 1 0 2 15 672 880 poll INs ?? 0:00.00 /usr/sbin/dhcpd Index: rc.subr =================================================================== RCS file: /cvs/src/etc/rc.d/rc.subr,v retrieving revision 1.70 diff -u -u -p -r1.70 rc.subr --- rc.subr 11 Jul 2013 09:34:33 -0000 1.70 +++ rc.subr 28 Dec 2013 21:02:51 -0000 @@ -1,4 +1,4 @@ -# $OpenBSD: rc.subr,v 1.70 2013/07/11 09:34:33 otto Exp $ +# $OpenBSD: rc.subr,v 1.14 2013/12/28 20:46:25 skinner Exp $ # # Copyright (c) 2010, 2011 Antoine Jacoutot <[email protected]> # Copyright (c) 2010, 2011 Ingo Schwarze <[email protected]> @@ -104,6 +104,28 @@ rc_wait() { return 1 } +rc_reprioritise() +{ + [[ ${_rcnice} == 'YES' ]] || + { + # nice(1): The priority can be adjusted over a + # range of -20 (the highest) to 20 (the lowest). + for _renice_level in $(jot 40 20 -20) + do + [[ ${_rcnice} == ${_renice_level} ]] && + { + _scheduling_priority=${_rcnice} + break + } + done + } + + # nice(1): an increment of 10 is assumed. + [[ -z ${_scheduling_priority} ]] && _scheduling_priority='10' + + renice -n ${_scheduling_priority} -p $(pgrep -f "^${pexp}") +} + rc_cmd() { local _bg _n @@ -136,6 +158,20 @@ rc_cmd() { fi [ -z "${INRC}" ] && rc_do rc_check && exit 0 echo $_n "${INRC:+ }${_name}" + + # sanitise _rcnice (only used for start) once before loop below + [[ ${_rcnice} == 'YES' ]] || + { + # if digits present + printf "%d" ${_rcnice} > /dev/null 2>&1 && + { + # strip non-digits for + # comparison in rc_reprioritise() + _rcnice=$(printf "%d" ${_rcnice}) + [[ ${_rcnice} -eq 0 ]] && unset _rcnice + } + } + while true; do # no real loop, only needed to break if type rc_pre >/dev/null; then rc_do rc_pre || break @@ -148,6 +184,7 @@ rc_cmd() { rc_do rc_wait start || break fi rc_do rc_write_runfile + [[ -n ${_rcnice} ]] && rc_do rc_reprioritise rc_exit ok done # handle failure @@ -203,6 +240,7 @@ _RC_RUNFILE=${_RC_RUNDIR}/${_name} eval _rcflags=\${${_name}_flags} eval _rcuser=\${${_name}_user} +eval _rcnice=\${${_name}_nice} getcap -f /etc/login.conf ${_name} 1>/dev/null 2>&1 && \ daemon_class=${_name} @@ -213,6 +251,7 @@ getcap -f /etc/login.conf ${_name} 1>/de [ -n "${_RC_FORCE}" ] && [ X"${_rcflags}" = X"NO" ] && unset _rcflags [ -n "${_rcflags}" ] && daemon_flags=${_rcflags} [ -n "${_rcuser}" ] && daemon_user=${_rcuser} +[[ ${_rcnice} == 'NO' ]] && unset _rcnice # sanitize daemon_flags=$(printf ' %s' ${daemon_flags}) Cheers, -- Craig Skinner | http://www.bbc.co.uk/programmes/b03mtrg9/clips
