# llxcfg-networking description "LliureX network upstart service" author "Luis Antonio Garcia Gisbert " start on ( started networking or llxnetworking-start ) stop on llxnetworking-stop emits llxnetworking-stop emits llxnet-start emits llxnet-stop script RUN_DIR="/var/run/llx-networking-done" AUTO_REGEXP="^[[:blank:]]*auto\b" NET_IFACES="/etc/network/interfaces" mkdir -p "$RUN_DIR" || true IFACE_LIST="" if [ -r "$NET_IFACES" ] ; then # find interfaces marked as auto in /etc/network/interfaces IFACE_LIST0=" $(sed -ne "/$AUTO_REGEXP/{s%$AUTO_REGEXP%%;p}" "$NET_IFACES") " # purge IFACE_LIST0 and build IFACE_LIST # - remove lo # - remove interfaces wihout an initialization line (iface ...) in /etc/network/interfaces # - remove nonexistent physical interfaces by 'grepping' in /proc/net/dev (for network aliases the ":ALIAS_NAME" part is removed first) for IFACE in $IFACE_LIST0 ; do if [ "$IFACE" != "lo" ] && grep -q "^[[:blank:]]*iface[[:blank:]]\+$IFACE\b" "$NET_IFACES" ; then PIFACE="${IFACE%:*}" ! grep -q "^[[:blank:]]*$PIFACE:" /proc/net/dev 2>/dev/null || IFACE_LIST="$IFACE_LIST $IFACE" fi done # for each interface, remove runfile in /var/run/llx-networking-done , and emit llxnet-stop/llxnet-start events # to trigger the apropiate llcfg-interface instances #for IFACE in $IFACE_LIST ; do # RUNFILE="$RUN_DIR/$IFACE" # /sbin/initctl emit llxnet-stop "IFACE=$IFACE" "RUNFILE=$RUNFILE" # sleep 1 # rm -f "$RUNFILE" || true # /sbin/initctl emit llxnet-start "IFACE=$IFACE" "RUNFILE=$RUNFILE" #done fi # wait until llcfg-interface instances terminate or a timeout of $MAX_TIME (120 secs) MAX_TIME=120 SLEEP_TIME=2 RUNNING_TIME=0 STOP_SERVICE="N" while : ; do STOP_SERVICE="Y" for IFACE in $IFACE_LIST ; do if [ ! -e "$RUN_DIR/$IFACE" ] ; then STOP_SERVICE="N" fi done if [ $RUNNING_TIME -gt $MAX_TIME ] || [ "$STOP_SERVICE" = "Y" ] ; then /sbin/initctl emit -n llxnetworking-stop break fi sleep $SLEEP_TIME RUNNING_TIME=$(($RUNNING_TIME + $SLEEP_TIME)) done end script post-stop script # echo "llxcfg-networking stop: $(date -R )" >> /root/net.log /sbin/initctl emit llxnet-stop-all /sbin/initctl emit llxnetworking-done end script