mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
Ticket: CM-1438 Reviewed By: reported by purna Testing Done: Tested with purna's l2 l3 lag test problem fixed by this patch: In some cases the child processes executing user cmds seem to hold on to the lock file fd for a lil longer, preventing another instance of ifupdown from running immediately after. Seen with two immediate instances of service networking restarts from scripts when the interfaces file has many user cmds.
213 lines
4.6 KiB
Bash
213 lines
4.6 KiB
Bash
#!/bin/bash
|
|
### BEGIN INIT INFO
|
|
# Provides: networking ifupdown
|
|
# Required-Start: mountkernfs $local_fs urandom
|
|
# Required-Stop: $local_fs
|
|
# Default-Start: S
|
|
# Default-Stop: 0 6
|
|
# Short-Description: Raise network interfaces.
|
|
# Description: Prepare /run/network directory, ifstate file and raise network interfaces, or take them down.
|
|
### END INIT INFO
|
|
|
|
PATH="/sbin:/bin"
|
|
RUN_DIR="/run/network"
|
|
IFSTATE="$RUN_DIR/ifstate"
|
|
|
|
[ -x /sbin/ifup ] || exit 0
|
|
[ -x /sbin/ifdown ] || exit 0
|
|
|
|
. /lib/lsb/init-functions
|
|
|
|
CONFIGURE_INTERFACES=yes
|
|
EXCLUDE_INTERFACES=
|
|
VERBOSE=no
|
|
|
|
verbose=
|
|
|
|
[ -f /etc/default/networking ] && . /etc/default/networking
|
|
|
|
[ "$VERBOSE" = yes ] && verbose=-v
|
|
|
|
gen_examples() {
|
|
# Generate sample interfaces file. The interfaces files are
|
|
# generated under /usr/share/doc/python-ifupdown2/examples/
|
|
#
|
|
|
|
# generate files only at boot
|
|
[ -f /var/tmp/network/ifstatenew ] && return
|
|
|
|
python_ifupdown2_docdir="/usr/share/doc/python-ifupdown2"
|
|
swpfile=${python_ifupdown2_docdir}"/examples/swp_defaults"
|
|
bridgedefaultfile=${python_ifupdown2_docdir}"/examples/bridge_untagged_default"
|
|
interfaces_gen_script=${python_ifupdown2_docdir}"/examples/generate_interfaces.py"
|
|
|
|
[ ! -e $interfaces_gen_script ] && return
|
|
ret=$($interfaces_gen_script -s 2>&1 >$swpfile)
|
|
ret=$($interfaces_gen_script -b 2>&1 >$bridgedefaultfile)
|
|
return
|
|
}
|
|
|
|
perf_options() {
|
|
# At bootup lets set perfmode
|
|
[ -f /var/tmp/network/ifstatenew ] && echo -n "" && return
|
|
|
|
echo -n "--perfmode"
|
|
}
|
|
|
|
process_exclusions() {
|
|
set -- $EXCLUDE_INTERFACES
|
|
exclusions=""
|
|
for d
|
|
do
|
|
exclusions="-X $d $exclusions"
|
|
done
|
|
echo $exclusions
|
|
}
|
|
|
|
check_network_file_systems() {
|
|
[ -e /proc/mounts ] || return 0
|
|
|
|
if [ -e /etc/iscsi/iscsi.initramfs ]; then
|
|
log_warning_msg "not deconfiguring network interfaces: iSCSI root is mounted."
|
|
exit 0
|
|
fi
|
|
|
|
while read DEV MTPT FSTYPE REST; do
|
|
case $DEV in
|
|
/dev/nbd*|/dev/nd[a-z]*|/dev/etherd/e*)
|
|
log_warning_msg "not deconfiguring network interfaces: network devices still mounted."
|
|
exit 0
|
|
;;
|
|
esac
|
|
case $FSTYPE in
|
|
nfs|nfs4|smbfs|ncp|ncpfs|cifs|coda|ocfs2|gfs|pvfs|pvfs2|fuse.httpfs|fuse.curlftpfs)
|
|
log_warning_msg "not deconfiguring network interfaces: network file systems still mounted."
|
|
exit 0
|
|
;;
|
|
esac
|
|
done < /proc/mounts
|
|
}
|
|
|
|
check_network_swap() {
|
|
[ -e /proc/swaps ] || return 0
|
|
|
|
while read DEV MTPT FSTYPE REST; do
|
|
case $DEV in
|
|
/dev/nbd*|/dev/nd[a-z]*|/dev/etherd/e*)
|
|
log_warning_msg "not deconfiguring network interfaces: network swap still mounted."
|
|
exit 0
|
|
;;
|
|
esac
|
|
done < /proc/swaps
|
|
}
|
|
|
|
ifup_hotplug () {
|
|
if [ -d /sys/class/net ]
|
|
then
|
|
ifaces=$(for iface in $(ifquery --list --allow=hotplug 2>/dev/null)
|
|
do
|
|
link=${iface##:*}
|
|
link=${link##.*}
|
|
if [ -e "/sys/class/net/$link" ] && [ "$(cat /sys/class/net/$link/operstate)" = up ]
|
|
then
|
|
echo "$iface"
|
|
fi
|
|
done)
|
|
if [ -n "$ifaces" ]
|
|
then
|
|
ifup $ifaces "$@" || true
|
|
fi
|
|
fi
|
|
}
|
|
|
|
ifupdown_init() {
|
|
[ ! -e /run/network ] && mkdir -p /run/network &>/dev/null
|
|
[ ! -e /etc/network/run ] && \
|
|
ln -sf /run/network /etc/network/run &>/dev/null
|
|
}
|
|
|
|
case "$1" in
|
|
start)
|
|
gen_examples
|
|
ifupdown_init
|
|
if [ "$CONFIGURE_INTERFACES" = no ]
|
|
then
|
|
log_action_msg "Not configuring network interfaces, see /etc/default/networking"
|
|
exit 0
|
|
fi
|
|
set -f
|
|
exclusions=$(process_exclusions)
|
|
perfoptions=$(perf_options)
|
|
log_action_begin_msg "Configuring network interfaces"
|
|
if ifup -a $verbose $perfoptions
|
|
then
|
|
log_action_end_msg $?
|
|
else
|
|
log_action_end_msg $?
|
|
fi
|
|
;;
|
|
|
|
stop)
|
|
ifupdown_init
|
|
check_network_file_systems
|
|
check_network_swap
|
|
|
|
log_action_begin_msg "Deconfiguring network interfaces"
|
|
if ifdown -a --exclude=lo $verbose; then
|
|
log_action_end_msg $?
|
|
else
|
|
log_action_end_msg $?
|
|
fi
|
|
;;
|
|
|
|
reload)
|
|
|
|
ifupdown_init
|
|
log_action_begin_msg "Reloading network interfaces configuration"
|
|
|
|
if ifreload -a
|
|
then
|
|
log_action_end_msg $?
|
|
else
|
|
log_action_end_msg $?
|
|
fi
|
|
;;
|
|
|
|
force-reload)
|
|
|
|
ifupdown_init
|
|
|
|
log_action_begin_msg "Reloading network interfaces configuration"
|
|
if ifreload -a
|
|
then
|
|
log_action_end_msg $?
|
|
else
|
|
log_action_end_msg $?
|
|
fi
|
|
;;
|
|
|
|
restart)
|
|
ifupdown_init
|
|
|
|
log_action_begin_msg "Reconfiguring network interfaces"
|
|
ifdown -a --exclude=lo $verbose || true
|
|
set -f
|
|
exclusions=$(process_exclusions)
|
|
if ifup -a --exclude=lo $verbose
|
|
then
|
|
log_action_end_msg $?
|
|
else
|
|
log_action_end_msg $?
|
|
fi
|
|
;;
|
|
|
|
*)
|
|
echo "Usage: /etc/init.d/networking {start|stop|reload|restart|force-reload}"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
exit 0
|
|
|
|
# vim: noet ts=8
|