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