diff options
author | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2011-03-09 09:10:45 +0000 |
---|---|---|
committer | Antoine Jacoutot <ajacoutot@cvs.openbsd.org> | 2011-03-09 09:10:45 +0000 |
commit | caa3601e4fa13bcec7cb29d1f57e612715d5bd9f (patch) | |
tree | a18b4b7fa475e0bf46d8ebd664d0e1f09324764d /etc | |
parent | 2b1fd2d004a68abfe394423c1aebb47e9c871393 (diff) |
Move rc_pre and rc_post out of the rc_start/rc_stop functions into the
rc_cmd start/stop actions. This way when rc.d(8) scripts override these
functions, we don't loose rc_{pre,post}.
Add a max 5 secs loop after rc_stop in the rc_cmd top action. This seems
to be a good default for returning to command line only after the daemon
has really stopped. This fixes "restart" for some daemons and allows to
properly stop some others at shutdown time.
Note that this is just a best-effort default, some daemons may need a
lot more time to shutdown but this case is usually handled in the
rc.d(8) script itself and we obviously do not want to hang the shutdown
process.
Call rc_cmd start/stop in restart and _not_ rc_start/rc_stop which can
get overriden in a script.
discussed with and inputs from sthen@ and schwarze@
ok sthen@ robert@
Diffstat (limited to 'etc')
-rw-r--r-- | etc/rc.d/rc.subr | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/etc/rc.d/rc.subr b/etc/rc.d/rc.subr index b236373e489..f9d7414af39 100644 --- a/etc/rc.d/rc.subr +++ b/etc/rc.d/rc.subr @@ -1,4 +1,4 @@ -# $OpenBSD: rc.subr,v 1.21 2011/03/06 16:49:48 ajacoutot Exp $ +# $OpenBSD: rc.subr,v 1.22 2011/03/09 09:10:44 ajacoutot Exp $ rc_err() { echo $1 @@ -6,7 +6,6 @@ rc_err() { } rc_start() { - type rc_pre >/dev/null && rc_pre ${rcexec} "${daemon} ${daemon_flags} >/dev/null ${_bg}" } @@ -20,7 +19,6 @@ rc_reload() { rc_stop() { pkill -f "^${pexp}" - type rc_post >/dev/null && rc_post || return 0 } rc_cmd() { @@ -37,20 +35,26 @@ rc_cmd() { rc_check ;; start) - rc_check || rc_start + if ! rc_check; then + type rc_pre >/dev/null && rc_pre + rc_start + fi ;; stop) rc_stop + i=0 + while [ $i -lt 5 ]; do + rc_check || break + sleep 1 + i=$((i+1)) + done + type rc_post >/dev/null && rc_post || return 0 ;; reload) rc_check && rc_reload ;; restart) - rc_stop - while rc_check; do - sleep 1 - done - rc_start + /etc/rc.d/${_name} stop && /etc/rc.d/${_name} start ;; *) rc_err "usage: $0 {start|check|reload|restart|stop}" |