source: llxcfg/trunk/fuentes/debian/llxcfg-runtime.llxcfg-networking.upstart @ 96

Last change on this file since 96 was 96, checked in by hectorgh, 5 years ago

adding proyect files

File size: 2.2 KB
Line 
1# llxcfg-networking
2
3description     "LliureX network upstart service"
4author          "Luis Antonio Garcia Gisbert <garcia_luigis@gva.es>"
5
6start on ( started networking or llxnetworking-start )
7stop on llxnetworking-stop
8
9emits llxnetworking-stop
10emits llxnet-start
11emits llxnet-stop
12
13script
14        RUN_DIR="/var/run/llx-networking-done"
15        AUTO_REGEXP="^[[:blank:]]*auto\b"
16        NET_IFACES="/etc/network/interfaces"
17        mkdir -p "$RUN_DIR" || true
18        IFACE_LIST=""
19        if [ -r "$NET_IFACES" ] ; then
20                # find interfaces marked as auto in /etc/network/interfaces
21                IFACE_LIST0=" $(sed -ne "/$AUTO_REGEXP/{s%$AUTO_REGEXP%%;p}" "$NET_IFACES") "
22
23                # purge IFACE_LIST0 and build IFACE_LIST
24                #       - remove lo
25                #       - remove interfaces wihout an initialization line (iface ...) in /etc/network/interfaces
26                #       - remove nonexistent physical interfaces by 'grepping' in /proc/net/dev (for network aliases the ":ALIAS_NAME" part is removed first)
27                for IFACE in $IFACE_LIST0 ; do
28                        if [ "$IFACE" != "lo" ] && grep -q "^[[:blank:]]*iface[[:blank:]]\+$IFACE\b" "$NET_IFACES" ; then
29                                PIFACE="${IFACE%:*}"
30                                ! grep -q "^[[:blank:]]*$PIFACE:" /proc/net/dev 2>/dev/null || IFACE_LIST="$IFACE_LIST $IFACE"
31                        fi
32                done
33
34                # for each interface, remove runfile in /var/run/llx-networking-done , and emit llxnet-stop/llxnet-start events
35                # to trigger the apropiate llcfg-interface instances
36                #for IFACE in $IFACE_LIST ; do
37                #       RUNFILE="$RUN_DIR/$IFACE"
38                #       /sbin/initctl emit llxnet-stop "IFACE=$IFACE" "RUNFILE=$RUNFILE"
39                #       sleep 1
40                #       rm -f "$RUNFILE" || true
41                #       /sbin/initctl emit llxnet-start "IFACE=$IFACE" "RUNFILE=$RUNFILE"
42                #done
43        fi
44
45        # wait until llcfg-interface instances terminate or a timeout of $MAX_TIME (120 secs)
46        MAX_TIME=120
47        SLEEP_TIME=2
48        RUNNING_TIME=0
49        STOP_SERVICE="N"
50        while : ; do
51                STOP_SERVICE="Y"       
52                for IFACE in $IFACE_LIST ; do
53                        if [ ! -e "$RUN_DIR/$IFACE" ] ; then
54                                STOP_SERVICE="N"
55                        fi
56                done
57                if [ $RUNNING_TIME -gt $MAX_TIME ] || [ "$STOP_SERVICE" = "Y" ] ; then
58                        /sbin/initctl emit -n llxnetworking-stop
59                        break
60                fi
61                sleep $SLEEP_TIME
62                RUNNING_TIME=$(($RUNNING_TIME + $SLEEP_TIME))
63        done
64
65end script
66
67post-stop script
68#       echo "llxcfg-networking stop: $(date -R )" >> /root/net.log
69        /sbin/initctl emit llxnet-stop-all
70        /sbin/initctl emit llxnetworking-done
71end script
72
Note: See TracBrowser for help on using the repository browser.