Add option to start network in background to speed up boot
authorHugo Villeneuve <hugo@hugovil.com>
Sun, 16 Feb 2014 18:03:50 +0000 (13:03 -0500)
committerHugo Villeneuve <hugo@hugovil.com>
Sun, 16 Feb 2014 18:03:50 +0000 (13:03 -0500)
stage2/bootscripts/network

index 70ac088..11c273a 100755 (executable)
@@ -11,6 +11,8 @@ source /etc/rc.d/init.d/functions
 
 log_script_name "$0 $*"
 
+BACKGROUND_START=yes
+
 # Load global network parameters
 source /etc/sysconfig/network/network-parameters
 
@@ -23,36 +25,79 @@ fi
 CWD=`pwd`
 cd /etc/sysconfig/network
 
+clean_network_up_indication()
+{
+    if [ -f "${NETWORKING_UP_FILE}" ]; then
+        rm "${NETWORKING_UP_FILE}"
+    fi
+}
+
+network_start()
+{
+    NUMBER_OF_IF_STARTED=0
+    NUMBER_OF_IF_TO_START=$(echo ${INTERFACES_UP} | wc -w)
+
+    for i in ${INTERFACES_UP}; do
+       if LANG=C egrep -q -L "^ONBOOT=\"?[Yy][Ee][Ss]\"?" ifconfig.$i ; then
+            local STR="Ethernet Adapter <$i> init"
+            local CMD="/etc/rc.d/init.d/ifup $i"
+
+            if [ x"${BACKGROUND_START}" == xyes ]; then
+                cmd_run_log ${CMD}
+            else
+                cmd_run_log_box_warn "${STR}" ${CMD}
+            fi
+
+           if [ ${?} -eq 0 ]; then
+                NUMBER_OF_IF_STARTED=$((NUMBER_OF_IF_STARTED + 1))
+           fi
+       fi
+    done
+
+    if [ "x${NUMBER_OF_IF_STARTED}" == "x${NUMBER_OF_IF_TO_START}" ]; then
+            # Signal to other scripts that all network interfaces have been
+            # started (especially usefull to prevent mountnetfs bootscript to
+            # blovk forever)
+        touch "${NETWORKING_UP_FILE}"
+    fi
+}
+
 # See how we were called.
 case "$1" in
     start)
-       for i in ${INTERFACES_UP}; do
-           if LANG=C egrep -L "^ONBOOT=\"?[Yy][Ee][Ss]\"?" ifconfig.$i >/dev/null 2>&1 ; then
-               cmd_run_log_box_warn "Ethernet Adapter <$i> init" /etc/rc.d/init.d/ifup "$i"
-           fi
-       done
+        clean_network_up_indication
+
+        if [ x"${BACKGROUND_START}" == xyes ]; then
+            network_start &
+        else
+            network_start
+        fi
         ;;
-    
+
     stop)
+        clean_network_up_indication
+
        for i in ${INTERFACES_DN} ; do
-           if LC_ALL= LANG= ip link show dev $i 2> /dev/null | grep -q "UP" >/dev/null 2>&1 ; then
-               cmd_run_log_box_warn "Ethernet Adapter <$i> stop" /etc/rc.d/init.d/ifdown "$i"
+           if LC_ALL= LANG= ip link show dev $i 2> /dev/null | grep -q "UP";
+            then
+               cmd_run_log_box_warn "Ethernet Adapter <$i> stop" \
+                    /etc/rc.d/init.d/ifdown "$i"
            fi
        done
         ;;
-    
+
     restart)
         cd $CWD
        $0 stop
        $0 start
        ;;
-    
+
     status)
        echo "Active devices:"
         /sbin/ip -oneline addr show up | grep inet \
            | sed 's/\(^.*\): \([a-zA-Z0-9]*\) *inet \([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\).*/   \2 (\3)/'
        ;;
-    
+
     *)
         echo $"Usage: $0 {start|stop|restart|status}"
        exit ${EXIT_CODE_FAILURE}