]> git.proxmox.com Git - mirror_ifupdown2.git/blame - init.d/networking
Add exclude args to /etc/default/networking
[mirror_ifupdown2.git] / init.d / networking
CommitLineData
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
12PATH="/sbin:/bin"
13RUN_DIR="/run/network"
14IFSTATE="$RUN_DIR/ifstate"
15
3808becf
RP
16NAME=networking
17SCRIPTNAME=/etc/init.d/$NAME
18
a6f80f0e 19[ -x /sbin/ifup ] || exit 0
20[ -x /sbin/ifdown ] || exit 0
21
22. /lib/lsb/init-functions
23
24CONFIGURE_INTERFACES=yes
a6f80f0e 25
261379f0 26EXTRA_ARGS=
579b3f25 27
a6f80f0e 28[ -f /etc/default/networking ] && . /etc/default/networking
29
261379f0
RP
30[ "$VERBOSE" = yes ] && EXTRA_ARGS=-v
31[ "$DEBUG" = yes ] && EXTRA_ARGS="$EXTRA_ARGS -d"
32[ "$SYSLOG" = yes ] && EXTRA_ARGS="$EXTRA_ARGS --syslog"
a6f80f0e 33
883f7f83 34gen_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
e938bfec 53perf_options() {
54 # At bootup lets set perfmode
45aa75e8
WK
55 [ -f /var/tmp/network/ifstatenew ] && echo -n "" && return
56
57 echo -n "--perfmode"
e938bfec 58}
59
a6f80f0e 60process_exclusions() {
61 set -- $EXCLUDE_INTERFACES
62 exclusions=""
63 for d
64 do
65 exclusions="-X $d $exclusions"
66 done
67 echo $exclusions
68}
69
a6f80f0e 70check_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
94check_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
107ifup_hotplug () {
108 if [ -d /sys/class/net ]
109 then
3e8ee54f 110 ifaces=$(for iface in $(ifquery --list --allow=hotplug 2>/dev/null)
a6f80f0e 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
37c0543d 126ifupdown_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
a6f80f0e 132case "$1" in
133start)
883f7f83 134 gen_examples
37c0543d 135 ifupdown_init
a6f80f0e 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)
e938bfec 143 perfoptions=$(perf_options)
a6f80f0e 144 log_action_begin_msg "Configuring network interfaces"
6ab14132
RP
145 echo "ifup -a $EXTRA_ARGS $exclusions $perfoptions"
146 ifup -a $EXTRA_ARGS $exclusions $perfoptions
3808becf 147 log_action_end_msg $?
a6f80f0e 148 ;;
149
150stop)
37c0543d 151 ifupdown_init
a6f80f0e 152 check_network_file_systems
153 check_network_swap
6ab14132 154 exclusions=$(process_exclusions)
a6f80f0e 155
156 log_action_begin_msg "Deconfiguring network interfaces"
6ab14132 157 ifdown -a $EXTRA_ARGS $exclusions
acc7dbc5 158 log_action_end_msg $?
a6f80f0e 159 ;;
160
161reload)
a6f80f0e 162
37c0543d 163 ifupdown_init
164 log_action_begin_msg "Reloading network interfaces configuration"
165
261379f0 166 ifreload -a $EXTRA_ARGS
acc7dbc5 167 log_action_end_msg $?
37c0543d 168 ;;
169
170force-reload)
171
172 ifupdown_init
173
a6f80f0e 174 log_action_begin_msg "Reloading network interfaces configuration"
acc7dbc5
RP
175 ifreload -a
176 log_action_end_msg $?
a6f80f0e 177 ;;
178
37c0543d 179restart)
37c0543d 180 ifupdown_init
181
a6f80f0e 182 set -f
183 exclusions=$(process_exclusions)
6ab14132
RP
184 log_action_begin_msg "Reconfiguring network interfaces"
185 ifdown -a $EXTRA_ARGS $exclusions || true
186 ifup -a $EXTRA_ARGS $exclusions
acc7dbc5 187 log_action_end_msg $?
a6f80f0e 188 ;;
189
190*)
191 echo "Usage: /etc/init.d/networking {start|stop|reload|restart|force-reload}"
192 exit 1
193 ;;
194esac
195
196exit 0
197
198# vim: noet ts=8