~ubuntu-branches/ubuntu/quantal/open-iscsi/quantal

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# iscsi-network-interface - suppress configuration of network interface used
# by iSCSI root device
#
# If the root filesystem is on iSCSI, then we must take care to avoid
# changing the state of its network interface. To this end, the initramfs
# leaves a note for us which interface was used, and we mangle
# /run/network/ifstate manually to stop it being brought up or down
# automatically. This is a slight layering violation, but, unfortunately,
# ifupdown appears to have no way to do this without also running
# /etc/network/*.d/ scripts.

description	"configure network device used by iSCSI root"

start on starting network-interface
stop on stopping network-interface

pre-start script
    CR="
"
    ifile=/run/initramfs/open-iscsi.interface
    if [ -f "$ifile" ] && read iface < "$ifile" &&
       ! grep -qs "^$iface=" /run/network/ifstate; then
        mkdir -p /run/network
        echo "$iface=$iface" >>/run/network/ifstate

        if [ -x /etc/network/if-up.d/upstart ]; then
            IFACE=$iface LOGICAL=$iface ADDRFAM=inet METHOD=manual /etc/network/if-up.d/upstart
        fi

        if command -v resolvconf >/dev/null &&
           [ -f /run/net-$iface.conf ]; then
            . "/run/net-$iface.conf"
            R=""
            [ -n "$DOMAINSEARCH" ] && R="$R${CR}domainsearch $DOMAINSEARCH"
            for ns in "$IPV4DNS0" "$IPV4DNS1"; do
                [ -n "$ns" -a "$ns" != "0.0.0.0" ] && R="$R${CR}nameserver $ns"
            done
            [ -z "${R}" ] || resolvconf -a $iface.iscsi-network <<EOF
${R#${CR}}
EOF
        fi
    fi
end script

post-stop script
    ifile=/run/initramfs/open-iscsi.interface
    if [ -f "$ifile" ] && read iface < "$ifile" &&
       grep -qs "^$iface=" /run/network/ifstate; then
        grep -v "^$iface=" /run/network/ifstate >/run/network/.ifstate.tmp || true
        mv /run/network/.ifstate.tmp /run/network/ifstate

        if command -v resolvconf >/dev/null; then
            resolvconf -d $iface.iscsi-network
        fi
    fi
end script