]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
networking.service: use start-networking script to control start/stop/reload
authorJulien Fortin <julien@cumulusnetworks.com>
Wed, 13 May 2020 18:47:47 +0000 (20:47 +0200)
committerJulien Fortin <julien@cumulusnetworks.com>
Wed, 13 May 2020 18:47:47 +0000 (20:47 +0200)
Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
debian/changelog
debian/ifupdown2.networking.service
etc/default/networking [new file with mode: 0644]
ifupdown2/sbin/start-networking [new file with mode: 0644]
setup.py

index a62cd1dfbe443d6f24ce162caf0944cddc9847a1..b183916aea2ac02bb9310108b8647631deda93a3 100644 (file)
@@ -1,6 +1,7 @@
 ifupdown2 (3.0.1-1) unstable; urgency=medium
 
    * New. Enabled: ES bond with "es-sys-mac" attribute
+   * Fix: start-networking script is back to handle mgmt & hotplug cases
 
  -- Julien Fortin <julien@cumulusnetworks.com>  Tue, 14 Apr 2020 23:42:42 +0200
 
index b2acd97aca9bec72241c530d7ca0a3c9b5f84df3..32f21f6b803ea7d44938a2c210aecee18a575b4c 100644 (file)
@@ -10,9 +10,10 @@ Type=oneshot
 RemainAfterExit=yes
 SyslogIdentifier=networking
 TimeoutStopSec=30s
-ExecStart=/sbin/ifup -a
-ExecStop=/sbin/ifdown -a
-ExecReload=/sbin/ifreload -a
+EnvironmentFile=/etc/default/networking
+ExecStart=/usr/share/ifupdown2/sbin/start-networking start
+ExecStop=/usr/share/ifupdown2/sbin/start-networking stop
+ExecReload=/usr/share/ifupdown2/sbin/start-networking reload
 
 [Install]
 WantedBy=basic.target network.target shutdown.target
diff --git a/etc/default/networking b/etc/default/networking
new file mode 100644 (file)
index 0000000..3a96199
--- /dev/null
@@ -0,0 +1,25 @@
+#
+#
+# Parameters for:
+#              - /etc/init.d/networking script
+#              - systemd networking service
+#
+#
+
+# Change the below to yes if you want verbose logging to be enabled
+VERBOSE="no"
+
+# Change the below to yes if you want debug logging to be enabled
+DEBUG="no"
+
+# Change the below to yes if you want logging to go to syslog
+SYSLOG="no"
+
+# Exclude interfaces
+EXCLUDE_INTERFACES=
+
+# Set to 'yes' if you want to skip ifdown during system reboot
+# and shutdown. This is of interest in large scale interface
+# deployments where you dont want to wait for interface
+# deconfiguration to speed up shutdown/reboot
+SKIP_DOWN_AT_SYSRESET="yes"
diff --git a/ifupdown2/sbin/start-networking b/ifupdown2/sbin/start-networking
new file mode 100644 (file)
index 0000000..d628a2c
--- /dev/null
@@ -0,0 +1,167 @@
+#!/bin/bash
+
+# This replaces the old init.d script, and is run from the networking.service
+# Only has start, stop, reload, because that's all systemd has.
+# restart is implemented in systemd by stop then start.
+
+RUN_DIR="/run/network"
+IFSTATE_LOCKFILE="${RUN_DIR}/ifstatelock"
+
+STATE_DIR="/var/tmp/network"
+IFSTATE_FILE="${STATE_DIR}/ifstatenew"
+
+NAME=networking
+
+[ -x /sbin/ifup ] || exit 0
+[ -x /sbin/ifdown ] || exit 0
+
+CONFIGURE_INTERFACES=yes
+
+EXTRA_ARGS=
+EXTRA_ARGS=
+
+[ "$VERBOSE" = yes ] && EXTRA_ARGS=-v
+[ "$DEBUG" = yes ] && EXTRA_ARGS="$EXTRA_ARGS -d"
+[ "$SYSLOG" = yes ] && EXTRA_ARGS="$EXTRA_ARGS --syslog"
+
+perf_options() {
+    # At bootup lets set perfmode
+    [ -f ${IFSTATE_LOCKFILE} ] && 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
+       echo ${NAME}':' "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*)
+           echo ${NAME}':' "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)
+           echo ${NAME}':' "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*)
+           echo ${NAME}':' "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" ]
+                                   then
+                                       echo "$iface"
+                                   fi
+                           done)
+           if [ -n "$ifaces" ]
+           then
+               ifup $ifaces "$@" || true
+           fi
+    fi
+}
+
+ifup_mgmt () {
+       ifaces=$(ifquery --list --allow=mgmt 2>/dev/null)
+       if [ -n "$ifaces" ]; then
+               echo "bringing up mgmt class interfaces"
+               ifup --allow=mgmt
+       fi
+}
+
+ifupdown_init() {
+       # remove state file at boot
+       [ ! -e ${IFSTATE_LOCKFILE} ] && rm -f ${IFSTATE_FILE}
+
+       [ ! -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)
+       ifupdown_init
+       if [ "$CONFIGURE_INTERFACES" = no ]
+       then
+           echo ${NAME}':' "Not configuring network interfaces, see /etc/default/networking"
+           exit 0
+       fi
+       set -f
+       exclusions=$(process_exclusions)
+       perfoptions=$(perf_options)
+       echo ${NAME}':' "Configuring network interfaces"
+       ifup_mgmt
+       ifup -a $EXTRA_ARGS $exclusions $perfoptions
+       ifup_hotplug $HOTPLUG_ARGS $EXTRA_ARGS $exclusions
+       ;;
+stop)
+       if [ "$SKIP_DOWN_AT_SYSRESET" = "yes" ]; then
+        SYSRESET=0
+        systemctl list-jobs | egrep -q '(shutdown|reboot|halt|poweroff)\.target'
+        [ $? -eq 0 ] && SYSRESET=1
+        if [ $SYSRESET -eq 1 ]; then
+            echo ${NAME}':' "Skipping deconfiguring network interfaces"
+            exit 0
+        fi
+       fi
+       ifupdown_init
+       check_network_file_systems
+       check_network_swap
+       exclusions=$(process_exclusions)
+
+       echo ${NAME}':' "Deconfiguring network interfaces"
+       ifdown -a $EXTRA_ARGS $exclusions
+       ;;
+
+reload)
+
+       ifupdown_init
+       exclusions=$(process_exclusions)
+
+       echo ${NAME}':' "Reloading network interfaces configuration"
+       ifreload -a $EXTRA_ARGS $exclusions
+       ;;
+
+*)
+       echo ${NAME}':' "Usage: $0 {start|stop|reload}"
+       exit 1
+       ;;
+esac
+
+exit 0
index 4c342c9ba73d7b2abdd43eb307ae5872e3439eba..6b41a4525bc734358295478f48187907b43ce449 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -10,8 +10,10 @@ INSTALL_REQUIRES = [
 ]
 
 DATA_FILES = [
+    ('/etc/default/', ['etc/default/networking']),
     ('/etc/network/ifupdown2/', ['etc/network/ifupdown2/addons.conf']),
     ('/etc/network/ifupdown2/', ['etc/network/ifupdown2/ifupdown2.conf']),
+    ('/usr/share/ifupdown2/sbin/', ['ifupdown2/sbin/start-networking'])
 ]
 
 SCRIPTS = []