Browse Source

Finally make it possible to restart/stop a daemon after having changed

its _flags in rc.conf(8).
When the rc.d(8) system starts a daemon, it will record its pexp under
/var/run/rc.d/rcscriptname and use that to interact with it (errors in
creating /var/run/rc.d or missing pexp file are non fatal, the framework
will just fallback to what it currently does).
deraadt@ doesn't mind a long as it doesn't come in the way of people
manually managing their daemons.
discussed with and input from sthen@ halex@ robert@ schwarze@
ok sthen@ robert@
OPENBSD_5_1
ajacoutot 13 years ago
parent
commit
1c38ab8e2d
1 changed files with 22 additions and 1 deletions
  1. +22
    -1
      src/etc/rc.d/rc.subr

+ 22
- 1
src/etc/rc.d/rc.subr View File

@ -1,4 +1,4 @@
# $OpenBSD: rc.subr,v 1.51 2011/10/07 07:26:49 ajacoutot Exp $
# $OpenBSD: rc.subr,v 1.52 2011/10/09 08:48:53 ajacoutot Exp $
# #
# Copyright (c) 2010, 2011 Antoine Jacoutot <ajacoutot@openbsd.org> # Copyright (c) 2010, 2011 Antoine Jacoutot <ajacoutot@openbsd.org>
# Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org> # Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@ -28,6 +28,19 @@ rc_usage() {
rc_err "usage: $0 [-df] {start|check|reload|restart|stop}" rc_err "usage: $0 [-df] {start|check|reload|restart|stop}"
} }
rc_write_runfile() {
[ -d ${_RC_RUNDIR} ] || mkdir -p ${_RC_RUNDIR} && \
print -rn -- "${pexp}" > ${_RC_RUNFILE}
}
rc_read_runfile() {
[ -f ${_RC_RUNFILE} ] && pexp=$(< ${_RC_RUNFILE})
}
rc_rm_runfile() {
[ -f ${_RC_RUNFILE} ] && rm ${_RC_RUNFILE}
}
rc_start() { rc_start() {
${rcexec} "${daemon} ${daemon_flags} ${_bg}" ${rcexec} "${daemon} ${daemon_flags} ${_bg}"
} }
@ -88,6 +101,8 @@ rc_cmd() {
[ X"${rc_bg}" = X"YES" ] && local _bg="&" [ X"${rc_bg}" = X"YES" ] && local _bg="&"
[ -n "${_RC_DEBUG}" ] || local _n="-n" [ -n "${_RC_DEBUG}" ] || local _n="-n"
rc_do rc_read_runfile
case "$1" in case "$1" in
check) check)
rc_do rc_check rc_do rc_check
@ -106,10 +121,12 @@ rc_cmd() {
sleep 1 sleep 1
rc_do rc_wait start || break rc_do rc_wait start || break
fi fi
rc_do rc_write_runfile
rc_exit ok rc_exit ok
done done
# handle failure # handle failure
type rc_post >/dev/null && rc_do rc_post type rc_post >/dev/null && rc_do rc_post
rc_do rc_rm_runfile
rc_exit failed rc_exit failed
;; ;;
stop) stop)
@ -120,6 +137,7 @@ rc_cmd() {
if type rc_post >/dev/null; then \ if type rc_post >/dev/null; then \
rc_do rc_post || rc_exit failed rc_do rc_post || rc_exit failed
fi fi
rc_do rc_rm_runfile
rc_exit ok rc_exit ok
;; ;;
reload) reload)
@ -156,6 +174,9 @@ done
shift $((OPTIND-1)) shift $((OPTIND-1))
_name=$(basename $0) _name=$(basename $0)
_RC_RUNDIR=/var/run/rc.d
_RC_RUNFILE=${_RC_RUNDIR}/${_name}
eval _rcflags=\${${_name}_flags} eval _rcflags=\${${_name}_flags}
eval _rcuser=\${${_name}_user} eval _rcuser=\${${_name}_user}


Loading…
Cancel
Save