diff --git a/elements/dhcp-all-interfaces/install.d/50-dhcp-all-interfaces b/elements/dhcp-all-interfaces/install.d/50-dhcp-all-interfaces index eaa51c71..06098735 100755 --- a/elements/dhcp-all-interfaces/install.d/50-dhcp-all-interfaces +++ b/elements/dhcp-all-interfaces/install.d/50-dhcp-all-interfaces @@ -9,6 +9,5 @@ DIB_INIT_SYSTEM=$(dib-init-system) if [ "$DIB_INIT_SYSTEM" == "upstart" ]; then install -D -g root -o root -m 0755 ${SCRIPTDIR}/dhcp-all-interfaces.conf /etc/init/dhcp-all-interfaces.conf elif [ "$DIB_INIT_SYSTEM" == "systemd" ]; then - install -D -g root -o root -m 0755 ${SCRIPTDIR}/dhcp-all-interfaces.service /usr/lib/systemd/system/dhcp-all-interfaces.service - systemctl enable dhcp-all-interfaces.service + install -D -g root -o root -m 0644 ${SCRIPTDIR}/udev.rules /etc/udev/rules.d/99-dhcp-all-interfaces.rules fi diff --git a/elements/dhcp-all-interfaces/install.d/dhcp-all-interfaces.service b/elements/dhcp-all-interfaces/install.d/dhcp-all-interfaces.service deleted file mode 100644 index e19c9240..00000000 --- a/elements/dhcp-all-interfaces/install.d/dhcp-all-interfaces.service +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=DHCP All Interfaces Service -Wants=local-fs.target systemd-udev-settle.service -After=local-fs.target systemd-udev-settle.service -Before=network.service - -[Service] -Type=oneshot -ExecStart=/usr/local/sbin/dhcp-all-interfaces.sh -RemainAfterExit=yes - -[Install] -WantedBy=multi-user.target -Alias=dhcp-all-interfaces.service diff --git a/elements/dhcp-all-interfaces/install.d/dhcp-all-interfaces.sh b/elements/dhcp-all-interfaces/install.d/dhcp-all-interfaces.sh index 7d53352d..dcfc4e74 100755 --- a/elements/dhcp-all-interfaces/install.d/dhcp-all-interfaces.sh +++ b/elements/dhcp-all-interfaces/install.d/dhcp-all-interfaces.sh @@ -1,7 +1,10 @@ #!/bin/bash +INTERFACE=${1:-} #optional, if not specified configure all available interfaces ENI_FILE="/etc/network/interfaces" +PATH=/sbin:$PATH + if [ -d "/etc/network" ]; then CONF_TYPE="eni" elif [ -d "/etc/sysconfig/network-scripts/" ]; then @@ -13,9 +16,9 @@ fi if [ "$CONF_TYPE" == "eni" ]; then # Serialize runs so that we don't miss hot-add interfaces - FLOCK=${1:-} - if [ -z "$FLOCK" ] ; then - exec flock -x $ENI_FILE $0 flocked + FLOCKED=${FLOCKED:-} + if [ -z "$FLOCKED" ] ; then + FLOCKED=true exec flock -x $ENI_FILE $0 fi fi @@ -63,16 +66,17 @@ function config_exists() { fi } -for interface in $(ls /sys/class/net | grep -v ^lo$) ; do - MAC_ADDR_TYPE="$(cat /sys/class/net/${interface}/addr_assign_type)" +function inspect_interface() { + local interface=$1 + local mac_addr_type="$(cat /sys/class/net/${interface}/addr_assign_type)" echo -n "Inspecting interface: $interface..." if config_exists $interface; then echo "Has config, skipping." - elif [ "$MAC_ADDR_TYPE" != "0" ]; then + elif [ "$mac_addr_type" != "0" ]; then echo "Device has generated MAC, skipping." - else - ip link set dev $interface up >/dev/null 2>&1 + else + ip link set dev $interface up &>/dev/null HAS_LINK="$(get_if_link $interface)" TRIES=10 @@ -91,4 +95,13 @@ for interface in $(ls /sys/class/net | grep -v ^lo$) ; do disable_interface "$interface" fi fi -done + +} + +if [ -n "$INTERFACE" ]; then + inspect_interface $INTERFACE +else + for iface in $(ls /sys/class/net | grep -v ^lo$); do + inspect_interface $iface + done +fi diff --git a/elements/dhcp-all-interfaces/install.d/udev.rules b/elements/dhcp-all-interfaces/install.d/udev.rules new file mode 100644 index 00000000..88ce3e13 --- /dev/null +++ b/elements/dhcp-all-interfaces/install.d/udev.rules @@ -0,0 +1 @@ +SUBSYSTEM=="net", ACTION=="add", RUN+="/usr/local/sbin/dhcp-all-interfaces.sh $name", RUN+="/sbin/ifup $name"