]>
Commit | Line | Data |
---|---|---|
2c8c4ce7 RP |
1 | #!/bin/bash |
2 | ### BEGIN INIT INFO | |
3 | # Provides: networking ifupdown | |
4 | # Required-Start: mountkernfs $local_fs urandom | |
5 | # Required-Stop: $local_fs | |
6 | # Default-Start: S | |
7 | # Default-Stop: 0 6 | |
8 | # Short-Description: Raise network interfaces. | |
9 | # Description: Prepare /run/network directory, ifstate file and raise network interfaces, or take them down. | |
10 | ### END INIT INFO | |
11 | ||
12 | PATH="/sbin:/bin" | |
13 | RUN_DIR="/run/network" | |
14 | IFSTATE="$RUN_DIR/ifstate" | |
15 | ||
16 | NAME=networking | |
17 | SCRIPTNAME=/etc/init.d/$NAME | |
18 | ||
19 | [ -x /sbin/ifup ] || exit 0 | |
20 | [ -x /sbin/ifdown ] || exit 0 | |
21 | ||
22 | . /lib/lsb/init-functions | |
23 | ||
24 | CONFIGURE_INTERFACES=yes | |
2c8c4ce7 | 25 | |
f82758bf | 26 | EXTRA_ARGS= |
2c8c4ce7 RP |
27 | |
28 | [ -f /etc/default/networking ] && . /etc/default/networking | |
29 | ||
f82758bf RP |
30 | [ "$VERBOSE" = yes ] && EXTRA_ARGS=-v |
31 | [ "$DEBUG" = yes ] && EXTRA_ARGS="$EXTRA_ARGS -d" | |
32 | [ "$SYSLOG" = yes ] && EXTRA_ARGS="$EXTRA_ARGS --syslog" | |
2c8c4ce7 RP |
33 | |
34 | gen_examples() { | |
35 | # Generate sample interfaces file. The interfaces files are | |
36 | # generated under /usr/share/doc/python-ifupdown2/examples/ | |
37 | # | |
38 | ||
39 | # generate files only at boot | |
40 | [ -f /var/tmp/network/ifstatenew ] && return | |
41 | ||
42 | python_ifupdown2_docdir="/usr/share/doc/python-ifupdown2" | |
43 | swpfile=${python_ifupdown2_docdir}"/examples/swp_defaults" | |
44 | bridgedefaultfile=${python_ifupdown2_docdir}"/examples/bridge_untagged_default" | |
45 | interfaces_gen_script=${python_ifupdown2_docdir}"/examples/generate_interfaces.py" | |
46 | ||
47 | [ ! -e $interfaces_gen_script ] && return | |
48 | ret=$($interfaces_gen_script -s 2>&1 >$swpfile) | |
49 | ret=$($interfaces_gen_script -b 2>&1 >$bridgedefaultfile) | |
50 | return | |
51 | } | |
52 | ||
2c8c4ce7 RP |
53 | perf_options() { |
54 | # At bootup lets set perfmode | |
f82758bf RP |
55 | [ -f /var/tmp/network/ifstatenew ] && echo -n "" && return |
56 | ||
57 | echo -n "--perfmode" | |
2c8c4ce7 RP |
58 | } |
59 | ||
60 | process_exclusions() { | |
61 | set -- $EXCLUDE_INTERFACES | |
62 | exclusions="" | |
63 | for d | |
64 | do | |
65 | exclusions="-X $d $exclusions" | |
66 | done | |
67 | echo $exclusions | |
68 | } | |
69 | ||
70 | check_network_file_systems() { | |
71 | [ -e /proc/mounts ] || return 0 | |
72 | ||
73 | if [ -e /etc/iscsi/iscsi.initramfs ]; then | |
74 | log_warning_msg "not deconfiguring network interfaces: iSCSI root is mounted." | |
75 | exit 0 | |
76 | fi | |
77 | ||
78 | while read DEV MTPT FSTYPE REST; do | |
79 | case $DEV in | |
80 | /dev/nbd*|/dev/nd[a-z]*|/dev/etherd/e*) | |
81 | log_warning_msg "not deconfiguring network interfaces: network devices still mounted." | |
82 | exit 0 | |
83 | ;; | |
84 | esac | |
85 | case $FSTYPE in | |
86 | nfs|nfs4|smbfs|ncp|ncpfs|cifs|coda|ocfs2|gfs|pvfs|pvfs2|fuse.httpfs|fuse.curlftpfs) | |
87 | log_warning_msg "not deconfiguring network interfaces: network file systems still mounted." | |
88 | exit 0 | |
89 | ;; | |
90 | esac | |
91 | done < /proc/mounts | |
92 | } | |
93 | ||
94 | check_network_swap() { | |
95 | [ -e /proc/swaps ] || return 0 | |
96 | ||
97 | while read DEV MTPT FSTYPE REST; do | |
98 | case $DEV in | |
99 | /dev/nbd*|/dev/nd[a-z]*|/dev/etherd/e*) | |
100 | log_warning_msg "not deconfiguring network interfaces: network swap still mounted." | |
101 | exit 0 | |
102 | ;; | |
103 | esac | |
104 | done < /proc/swaps | |
105 | } | |
106 | ||
107 | ifup_hotplug () { | |
108 | if [ -d /sys/class/net ] | |
109 | then | |
110 | ifaces=$(for iface in $(ifquery --list --allow=hotplug 2>/dev/null) | |
111 | do | |
112 | link=${iface##:*} | |
113 | link=${link##.*} | |
114 | if [ -e "/sys/class/net/$link" ] && [ "$(cat /sys/class/net/$link/operstate)" = up ] | |
115 | then | |
116 | echo "$iface" | |
117 | fi | |
118 | done) | |
119 | if [ -n "$ifaces" ] | |
120 | then | |
121 | ifup $ifaces "$@" || true | |
122 | fi | |
123 | fi | |
124 | } | |
125 | ||
126 | ifupdown_init() { | |
127 | [ ! -e /run/network ] && mkdir -p /run/network &>/dev/null | |
128 | [ ! -e /etc/network/run ] && \ | |
129 | ln -sf /run/network /etc/network/run &>/dev/null | |
130 | } | |
131 | ||
132 | case "$1" in | |
133 | start) | |
134 | gen_examples | |
135 | ifupdown_init | |
136 | if [ "$CONFIGURE_INTERFACES" = no ] | |
137 | then | |
138 | log_action_msg "Not configuring network interfaces, see /etc/default/networking" | |
139 | exit 0 | |
140 | fi | |
141 | set -f | |
142 | exclusions=$(process_exclusions) | |
143 | perfoptions=$(perf_options) | |
144 | log_action_begin_msg "Configuring network interfaces" | |
f82758bf | 145 | ifup -a $EXTRA_ARGS $exclusions $perfoptions |
2c8c4ce7 RP |
146 | log_action_end_msg $? |
147 | ;; | |
148 | ||
149 | stop) | |
150 | ifupdown_init | |
151 | check_network_file_systems | |
152 | check_network_swap | |
f82758bf | 153 | exclusions=$(process_exclusions) |
2c8c4ce7 RP |
154 | |
155 | log_action_begin_msg "Deconfiguring network interfaces" | |
f82758bf RP |
156 | ifdown -a $EXTRA_ARGS $exclusions |
157 | log_action_end_msg $? | |
2c8c4ce7 RP |
158 | ;; |
159 | ||
160 | reload) | |
161 | ||
162 | ifupdown_init | |
163 | log_action_begin_msg "Reloading network interfaces configuration" | |
164 | ||
f82758bf RP |
165 | ifreload -a $EXTRA_ARGS |
166 | log_action_end_msg $? | |
167 | ;; | |
168 | ||
169 | reload-currently-up) | |
170 | ||
171 | ifupdown_init | |
172 | log_action_begin_msg "Reloading currently up network interfaces configuration" | |
173 | ||
174 | ifreload --currently-up $EXTRA_ARGS | |
175 | log_action_end_msg $? | |
2c8c4ce7 RP |
176 | ;; |
177 | ||
178 | force-reload) | |
179 | ||
180 | ifupdown_init | |
181 | ||
182 | log_action_begin_msg "Reloading network interfaces configuration" | |
f82758bf RP |
183 | ifreload -f -a $EXTRA_ARGS |
184 | log_action_end_msg $? | |
2c8c4ce7 RP |
185 | ;; |
186 | ||
187 | restart) | |
188 | ifupdown_init | |
189 | ||
2c8c4ce7 RP |
190 | set -f |
191 | exclusions=$(process_exclusions) | |
f82758bf RP |
192 | log_action_begin_msg "Reconfiguring network interfaces" |
193 | ifdown -a $EXTRA_ARGS $exclusions || true | |
194 | ifup -a $EXTRA_ARGS $exclusions | |
195 | log_action_end_msg $? | |
2c8c4ce7 RP |
196 | ;; |
197 | ||
198 | *) | |
199 | echo "Usage: /etc/init.d/networking {start|stop|reload|restart|force-reload}" | |
200 | exit 1 | |
201 | ;; | |
202 | esac | |
203 | ||
204 | exit 0 | |
205 | ||
206 | # vim: noet ts=8 |