Hello, rc.subr(8) uses pgrep(1)/pkill(1) to control daemons using their command lines.
But in some cases it is more convenient to use pidfiles. Many services do so, inluding apache and postgresql. But not all services do have special tool for that. I run gunicorn (python wsgi server) that is able to produce pidfile, but lacks of tool to control it. So, I added ``daemon_pidfile`` variable to rc.subr(8). If this variable is not set then everything works as usual. But if you set it then system uses it to check (ps -p), stop and reload (kill) daemon. I then simply tell gunicorn to write its pidfile and everything works. I believe this approach may be used by other rc scripts also. Diff below does not have man yet, and I am ready to write it if everyone would agree with my changes. Ilya. Index: etc/rc.d/rc.subr =================================================================== RCS file: /cvs/src/etc/rc.d/rc.subr,v retrieving revision 1.127 diff -u -p -u -r1.127 rc.subr --- etc/rc.d/rc.subr 5 Jun 2017 18:31:23 -0000 1.127 +++ etc/rc.d/rc.subr 2 Jun 2018 19:33:29 -0000 @@ -49,6 +49,7 @@ _rc_write_runfile() { cat >${_RC_RUNFILE} <<EOF daemon_class=${daemon_class} daemon_flags=${daemon_flags} +daemon_pidfile=${daemon_pidfile} daemon_rtable=${daemon_rtable} daemon_timeout=${daemon_timeout} daemon_user=${daemon_user} @@ -174,15 +175,27 @@ rc_start() { } rc_check() { - pgrep -T "${daemon_rtable}" -q -xf "${pexp}" + if [ -z ${daemon_pidfile} ]; then + pgrep -T "${daemon_rtable}" -q -xf "${pexp}" + else + [ -f ${daemon_pidfile} ] && ps -p $(cat ${daemon_pidfile}) + fi } rc_reload() { - pkill -HUP -T "${daemon_rtable}" -xf "${pexp}" + if [ -z ${daemon_pidfile} ]; then + pkill -HUP -T "${daemon_rtable}" -xf "${pexp}" + else + [ -f ${daemon_pidfile} ] && kill -HUP $(cat ${daemon_pidfile}) + fi } rc_stop() { - pkill -T "${daemon_rtable}" -xf "${pexp}" + if [ -z ${daemon_pidfile} ]; then + pkill -T "${daemon_rtable}" -xf "${pexp}" + else + [ -f ${daemon_pidfile} ] && kill -TERM $(cat ${daemon_pidfile}) + fi } rc_cmd() { @@ -287,6 +300,7 @@ _RC_RUNFILE=${_RC_RUNDIR}/${_name} # parse /etc/rc.conf{.local} for the daemon_flags _rc_do _rc_parse_conf +eval _rcpidfile=\${${_name}_pidfile} eval _rcflags=\${${_name}_flags} eval _rcrtable=\${${_name}_rtable} eval _rcuser=\${${_name}_user} @@ -303,6 +317,7 @@ getcap -f /etc/login.conf ${_name} 1>/de [ -n "${_RC_FORCE}" -o "$1" != "start" ] && [ X"${_rcflags}" = X"NO" ] && unset _rcflags +[ -n "${_rcpidfile}" ] && daemon_pidfile=${_rcpidfile} [ -n "${_rcflags}" ] && daemon_flags=${_rcflags} [ -n "${_rcrtable}" ] && daemon_rtable=${_rcrtable} [ -n "${_rcuser}" ] && daemon_user=${_rcuser}