Here is a draft patch to enable concurrent startup of boot scripts.
The output from the scripts will be mixed, so there should be some
wrapper make to serialize the output.  But it works, and allow the
administrator to customize the level of concurrency.  With
CONCURRENCY=1 it behaves almost as the current boot script.

I used diff -w to ignore whitespace changes, to extract the "meat" of
the diff.  The script need to be reindented if the patch is applied.

--- /etc/init.d/rc      2004-09-10 17:00:48.000000000 +0200
+++ rc  2005-09-05 23:27:23.762787592 +0200
@@ -18,6 +18,8 @@
 # Un-comment the following for debugging.
 # debug=echo
 
+CONCURRENCY=32
+
 #
 # Start script or program.
 #
@@ -59,17 +61,60 @@
        # First, run the KILL scripts.
        if [ $previous != N ]
        then
-               for i in /etc/rc$runlevel.d/K[0-9][0-9]*
+               # Run all scripts with the same level in parallell
+               for level in $(cd /etc/rc$runlevel.d ; ls K* | \
+                              sed 's/^K\([0-9][0-9]\).*/\1/' )
+               do
+                       if [ "$level" = "$CURLEVEL" ]
+                       then
+                               continue
+                       fi
+                       CURLEVEL=$level
+                       pids=""
+                       subs=0
+                       for i in /etc/rc$runlevel.d/K$level*
                do
                        # Check if the script is there.
                        [ ! -f $i ] && continue
 
                        # Stop the service.
-                       startup $i stop
+                               startup $i stop &
+                               pids="$pids $!"
+                               subs=$(($subs + 1))
+
+                               # Enough sub-processes running?
+                               if [ "$CONCURRENCY" -le "$subs" ]
+                               then
+                                       for pid in $pids
+                                       do
+                                               wait $pid
+                                               subs=$(($subs - 1))
+                                       done
+                                       pids=""
+                               fi
+                       done
+                       # Wait for all pids.  Does not matter which
+                       # pid return first, as we need to wait for all
+                       # of them
+                       for pid in $pids
+                       do
+                               wait $pid
+                       done
                done
        fi
        # Now run the START scripts for this runlevel.
-       for i in /etc/rc$runlevel.d/S*
+
+       # Run all scripts with the same level in parallell
+       for level in $(cd /etc/rc$runlevel.d ; ls S* | \
+                      sed 's/^S\([0-9][0-9]\).*/\1/' )
+       do
+               if [ "$level" = "$CURLEVEL" ]
+               then
+                       continue
+               fi
+               CURLEVEL=$level
+               pids=""
+               for i in /etc/rc$runlevel.d/S$level*
        do
                [ ! -f $i ] && continue
 
@@ -91,12 +136,21 @@
                fi
                case "$runlevel" in
                        0|6)
-                               startup $i stop
+                                       startup $i stop &
                                ;;
                        *)
-                               startup $i start
+                                       startup $i start &
                                ;;
                esac
+                       pids="$pids $!"
+               done
+               # Wait for all pids.  Does not matter which
+               # pid return first, as we need to wait for all
+               # of them
+               for pid in $pids
+               do
+                       wait $pid
+               done
        done
   fi
 # eof /etc/init.d/rc


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to