From f611213420cf4436838fa042720b7ce407d17ae4 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Fri, 13 Nov 2009 22:04:59 +0100 Subject: [PATCH] Add support for starting daemons in background, but maintain the order Signed-off-by: Florian Pritz --- functions | 20 ++++++++++++++++++++ rc.conf | 1 + rc.multi | 3 +++ rc.shutdown | 14 ++++++++++++-- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/functions b/functions index 4dca333..15ee693 100644 --- a/functions +++ b/functions @@ -197,10 +197,30 @@ start_daemon_bkgd() { (/etc/rc.d/$1 start) &>/dev/null & } +start_daemonbkg() { + (/etc/rc.d/$1 start) 2>&1 >/dev/null +} + +start_daemonbkg_bkgd() { + (/etc/rc.d/$1 start) 2>&1 >dev/null & +} + stop_daemon() { /etc/rc.d/$1 stop } +start_bkgdaemons() { + for daemon in "${DAEMONSBKG[@]}"; do + if [ "$daemon" = "${daemon#!}" ]; then + if [ "$daemon" = "${daemon#@}" ]; then + start_daemonbkg $daemon 2>&1 >/dev/null + else + start_daemonbkg_bkgd ${daemon:1} 2>&1 >/dev/null + fi + fi + done +} + # Status functions status_started() { deltext diff --git a/rc.conf b/rc.conf index 252a9b1..cf0dd0d 100644 --- a/rc.conf +++ b/rc.conf @@ -91,3 +91,4 @@ ROUTES=(!gateway) # - prefix a daemon with a @ to start it up in the background # DAEMONS=(syslog-ng network netfs crond) +DAEMONSBKG=() diff --git a/rc.multi b/rc.multi index a7ea703..7390787 100755 --- a/rc.multi +++ b/rc.multi @@ -22,6 +22,9 @@ for daemon in "${DAEMONS[@]}"; do fi done +# Start background daemons +start_bkgdaemons &> /dev/null & + if [ -x /etc/rc.local ]; then /etc/rc.local fi diff --git a/rc.shutdown b/rc.shutdown index b0de393..e39a020 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -24,14 +24,24 @@ if [ -x /etc/rc.local.shutdown ]; then /etc/rc.local.shutdown fi -# Find daemons NOT in the DAEMONS array. Shut these down first +# Find daemons NOT in the DAEMONS nor the DAEMONSBKG array. Shut these down first if [ -d /var/run/daemons ]; then for daemon in $(/bin/ls -1t /var/run/daemons); do - if ! in_array $daemon ${DAEMONS[@]}; then + if ! in_array $daemon ${DAEMONS[@]} ${DAEMONSBKG[@]}; then stop_daemon $daemon fi done fi + +# Shutdown background daemons in reverse order +let i=${#DAEMONSBKG[@]}-1 +while [ $i -ge 0 ]; do + if [ "${DAEMONSBKG[$i]:0:1}" != '!' ]; then + ck_daemon ${DAEMONSBKG[$i]#@} || stop_daemon ${DAEMONSBKG[$i]#@} + fi + let i=i-1 +done + # Shutdown daemons in reverse order let i=${#DAEMONS[@]}-1 while [ $i -ge 0 ]; do -- 1.6.5.4