]> git.proxmox.com Git - mirror_ifupdown2.git/blame - init.d/networking
Document ifreload new option + add it into init.d networking script
[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 145 ifup -a $EXTRA_ARGS $exclusions $perfoptions
3808becf 146 log_action_end_msg $?
a6f80f0e 147 ;;
148
149stop)
37c0543d 150 ifupdown_init
a6f80f0e 151 check_network_file_systems
152 check_network_swap
6ab14132 153 exclusions=$(process_exclusions)
a6f80f0e 154
155 log_action_begin_msg "Deconfiguring network interfaces"
6ab14132 156 ifdown -a $EXTRA_ARGS $exclusions
acc7dbc5 157 log_action_end_msg $?
a6f80f0e 158 ;;
159
160reload)
a6f80f0e 161
37c0543d 162 ifupdown_init
163 log_action_begin_msg "Reloading network interfaces configuration"
164
261379f0 165 ifreload -a $EXTRA_ARGS
acc7dbc5 166 log_action_end_msg $?
37c0543d 167 ;;
168
d462f1fa
RP
169reload-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 $?
176 ;;
177
37c0543d 178force-reload)
179
180 ifupdown_init
181
a6f80f0e 182 log_action_begin_msg "Reloading network interfaces configuration"
d462f1fa 183 ifreload -f -a $EXTRA_ARGS
acc7dbc5 184 log_action_end_msg $?
a6f80f0e 185 ;;
186
37c0543d 187restart)
37c0543d 188 ifupdown_init
189
a6f80f0e 190 set -f
191 exclusions=$(process_exclusions)
6ab14132
RP
192 log_action_begin_msg "Reconfiguring network interfaces"
193 ifdown -a $EXTRA_ARGS $exclusions || true
194 ifup -a $EXTRA_ARGS $exclusions
acc7dbc5 195 log_action_end_msg $?
a6f80f0e 196 ;;
197
198*)
199 echo "Usage: /etc/init.d/networking {start|stop|reload|restart|force-reload}"
200 exit 1
201 ;;
202esac
203
204exit 0
205
206# vim: noet ts=8