| 
									
										
										
										
											2014-05-19 07:00:12 -07:00
										 |  |  | #!/bin/bash | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | ### 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" | 
					
						
							| 
									
										
										
										
											2015-10-02 12:31:51 -07:00
										 |  |  | IFSTATE_LOCKFILE="${RUN_DIR}/ifstatelock" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | STATE_DIR="/var/tmp/network" | 
					
						
							|  |  |  | IFSTATE_FILE="${STATE_DIR}/ifstatenew" | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-09 20:23:21 -07:00
										 |  |  | NAME=networking | 
					
						
							|  |  |  | SCRIPTNAME=/etc/init.d/$NAME | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | [ -x /sbin/ifup ] || exit 0 | 
					
						
							|  |  |  | [ -x /sbin/ifdown ] || exit 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | . /lib/lsb/init-functions | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CONFIGURE_INTERFACES=yes | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 15:18:42 -08:00
										 |  |  | EXTRA_ARGS= | 
					
						
							| 
									
										
										
										
											2013-12-20 13:59:37 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | [ -f /etc/default/networking ] && . /etc/default/networking | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 15:18:42 -08:00
										 |  |  | [ "$VERBOSE" = yes ] && EXTRA_ARGS=-v | 
					
						
							|  |  |  | [ "$DEBUG" = yes ] && EXTRA_ARGS="$EXTRA_ARGS -d" | 
					
						
							|  |  |  | [ "$SYSLOG" = yes ] && EXTRA_ARGS="$EXTRA_ARGS --syslog" | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-19 07:00:12 -07:00
										 |  |  | gen_examples() { | 
					
						
							|  |  |  |     # Generate sample interfaces file. The interfaces files are | 
					
						
							|  |  |  |     # generated under /usr/share/doc/python-ifupdown2/examples/ | 
					
						
							|  |  |  |     # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # generate files only at boot | 
					
						
							| 
									
										
										
										
											2015-10-02 12:31:51 -07:00
										 |  |  |     [ -f ${IFSTATE_LOCKFILE} ] && return | 
					
						
							| 
									
										
										
										
											2014-05-19 07:00:12 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     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 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-20 13:11:22 -08:00
										 |  |  | perf_options() { | 
					
						
							|  |  |  |     # At bootup lets set perfmode | 
					
						
							| 
									
										
										
										
											2015-10-02 12:31:51 -07:00
										 |  |  |     [ -f ${IFSTATE_LOCKFILE} ] && echo -n "" && return | 
					
						
							| 
									
										
										
										
											2014-07-27 21:28:46 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     echo -n "--perfmode" | 
					
						
							| 
									
										
										
										
											2014-02-20 13:11:22 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | 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 | 
					
						
							| 
									
										
										
										
											2013-11-13 16:07:15 -08:00
										 |  |  | 	    ifaces=$(for iface in $(ifquery --list --allow=hotplug 2>/dev/null) | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | 			    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 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-30 22:36:41 -08:00
										 |  |  | ifupdown_init() { | 
					
						
							| 
									
										
										
										
											2015-10-02 12:31:51 -07:00
										 |  |  |     	# remove state file at boot | 
					
						
							|  |  |  | 	[ ! -e ${IFSTATE_LOCKFILE} ] && rm -f ${IFSTATE_FILE} | 
					
						
							| 
									
										
										
										
											2014-01-30 22:36:41 -08:00
										 |  |  | 	[ ! -e /run/network ] && mkdir -p /run/network &>/dev/null | 
					
						
							|  |  |  | 	[ ! -e /etc/network/run ] && \ | 
					
						
							|  |  |  | 		ln -sf /run/network /etc/network/run &>/dev/null | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | case "$1" in | 
					
						
							|  |  |  | start) | 
					
						
							| 
									
										
										
										
											2014-05-19 07:00:12 -07:00
										 |  |  |     	gen_examples | 
					
						
							| 
									
										
										
										
											2014-01-30 22:36:41 -08:00
										 |  |  | 	ifupdown_init | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | 	if [ "$CONFIGURE_INTERFACES" = no ] | 
					
						
							|  |  |  | 	then | 
					
						
							|  |  |  | 	    log_action_msg "Not configuring network interfaces, see /etc/default/networking" | 
					
						
							|  |  |  | 	    exit 0 | 
					
						
							|  |  |  | 	fi | 
					
						
							|  |  |  | 	set -f | 
					
						
							|  |  |  | 	exclusions=$(process_exclusions) | 
					
						
							| 
									
										
										
										
											2014-02-20 13:11:22 -08:00
										 |  |  | 	perfoptions=$(perf_options) | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | 	log_action_begin_msg "Configuring network interfaces" | 
					
						
							| 
									
										
										
										
											2014-11-18 16:58:12 -08:00
										 |  |  | 	ifup -a $EXTRA_ARGS $exclusions $perfoptions  | 
					
						
							| 
									
										
										
										
											2014-07-09 20:23:21 -07:00
										 |  |  | 	log_action_end_msg $? | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | 	;; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | stop) | 
					
						
							| 
									
										
										
										
											2015-05-12 07:32:53 -07:00
										 |  |  | 	if [ "$SKIP_DOWN_AT_SYSRESET" = "yes" ]; then | 
					
						
							|  |  |  | 		shutdown_or_reboot=$(runlevel 2>/dev/null | \ | 
					
						
							|  |  |  | 				     /usr/bin/tr -s " " | \ | 
					
						
							|  |  |  | 				     /usr/bin/cut -d " " \ | 
					
						
							|  |  |  | 				     -f1- --output-delimiter=$'\n' | \ | 
					
						
							|  |  |  | 				     /bin/grep -e "0" -e "6") | 
					
						
							|  |  |  | 		if [ -n "$shutdown_or_reboot" ]; then | 
					
						
							|  |  |  | 			log_action_begin_msg "Deconfiguring network interfaces..skip" | 
					
						
							|  |  |  | 			log_action_end_msg 0 | 
					
						
							|  |  |  | 			exit 0 | 
					
						
							|  |  |  | 		fi | 
					
						
							|  |  |  | 	fi | 
					
						
							| 
									
										
										
										
											2014-01-30 22:36:41 -08:00
										 |  |  | 	ifupdown_init | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | 	check_network_file_systems | 
					
						
							|  |  |  | 	check_network_swap | 
					
						
							| 
									
										
										
										
											2014-11-18 16:58:12 -08:00
										 |  |  | 	exclusions=$(process_exclusions) | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	log_action_begin_msg "Deconfiguring network interfaces" | 
					
						
							| 
									
										
										
										
											2014-11-18 16:58:12 -08:00
										 |  |  | 	ifdown -a $EXTRA_ARGS $exclusions | 
					
						
							| 
									
										
										
										
											2014-08-26 16:17:49 -07:00
										 |  |  | 	log_action_end_msg $? | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | 	;; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | reload) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-30 22:36:41 -08:00
										 |  |  | 	ifupdown_init | 
					
						
							|  |  |  | 	log_action_begin_msg "Reloading network interfaces configuration" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-07 15:18:42 -08:00
										 |  |  | 	ifreload -a $EXTRA_ARGS | 
					
						
							| 
									
										
										
										
											2014-08-26 16:17:49 -07:00
										 |  |  | 	log_action_end_msg $? | 
					
						
							| 
									
										
										
										
											2014-01-30 22:36:41 -08:00
										 |  |  | 	;; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-03 00:27:35 -08:00
										 |  |  | reload-currently-up) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ifupdown_init | 
					
						
							|  |  |  | 	log_action_begin_msg "Reloading currently up network interfaces configuration" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ifreload --currently-up $EXTRA_ARGS | 
					
						
							|  |  |  | 	log_action_end_msg $? | 
					
						
							|  |  |  | 	;; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-30 22:36:41 -08:00
										 |  |  | force-reload) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ifupdown_init | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | 	log_action_begin_msg "Reloading network interfaces configuration" | 
					
						
							| 
									
										
										
										
											2015-01-03 00:27:35 -08:00
										 |  |  | 	ifreload -f -a $EXTRA_ARGS | 
					
						
							| 
									
										
										
										
											2014-08-26 16:17:49 -07:00
										 |  |  | 	log_action_end_msg $? | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | 	;; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-30 22:36:41 -08:00
										 |  |  | restart) | 
					
						
							|  |  |  | 	ifupdown_init | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | 	set -f | 
					
						
							|  |  |  | 	exclusions=$(process_exclusions) | 
					
						
							| 
									
										
										
										
											2014-11-18 16:58:12 -08:00
										 |  |  | 	log_action_begin_msg "Reconfiguring network interfaces" | 
					
						
							|  |  |  | 	ifdown -a $EXTRA_ARGS $exclusions || true | 
					
						
							|  |  |  | 	ifup -a $EXTRA_ARGS $exclusions | 
					
						
							| 
									
										
										
										
											2014-08-26 16:17:49 -07:00
										 |  |  | 	log_action_end_msg $? | 
					
						
							| 
									
										
										
										
											2013-11-04 06:06:11 -08:00
										 |  |  | 	;; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | *) | 
					
						
							|  |  |  | 	echo "Usage: /etc/init.d/networking {start|stop|reload|restart|force-reload}" | 
					
						
							|  |  |  | 	exit 1 | 
					
						
							|  |  |  | 	;; | 
					
						
							|  |  |  | esac | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exit 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # vim: noet ts=8 |