From 72b56d0f59f321519f25b039937a24b0ce338295 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 18 Mar 2016 20:35:36 -0400 Subject: add this, its getting moved, but i wanted some of the content stored --- udev/79-cloud-init-net-setup-link.rules | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 udev/79-cloud-init-net-setup-link.rules (limited to 'udev') diff --git a/udev/79-cloud-init-net-setup-link.rules b/udev/79-cloud-init-net-setup-link.rules new file mode 100644 index 00000000..03dba382 --- /dev/null +++ b/udev/79-cloud-init-net-setup-link.rules @@ -0,0 +1,18 @@ +# cloud-init rules to apply + +SUBSYSTEM!="net", GOTO="cloudinit_naming_end" + +IMPORT{builtin}="path_id" + +ACTION!="add", GOTO="cloudinit_naming_end" + +# net_setup_link provides us with systemd names for reference +IMPORT{builtin}="net_setup_link" +ATTR{address}!="", ENV{MAC_ADDRESS}="$attr{address}" +IMPORT{program}="/lib/udev/cloud-init-name-device" + +ENV{CLOUDINIT_NET_NAME}!="", NAME="$env{CLOUDINIT_NET_NAME}" + +LABEL="cloudinit_naming_end" + +# vi: ts=4 expandtab syntax=udevrules -- cgit v1.2.3 From 519c0936e3e80fc14225e500fbb61d0d12d28c35 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 18 Mar 2016 20:40:54 -0400 Subject: commit the systemd waiting mechanism Note, still broken as cloud-init local is not going to ever touch the CI_NET_READY file (/run/cloud-init/network-config-ready). So as this is , it will actually just block for 60 seconds and go on. --- setup.py | 3 +- systemd/cloud-init-generator | 3 ++ udev/79-cloud-init-net-setup-link.rules | 18 -------- udev/79-cloud-init-net-wait.rules | 10 ++++ udev/cloud-init-wait | 82 +++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 19 deletions(-) delete mode 100644 udev/79-cloud-init-net-setup-link.rules create mode 100644 udev/79-cloud-init-net-wait.rules create mode 100755 udev/cloud-init-wait (limited to 'udev') diff --git a/setup.py b/setup.py index 0b261dfe..f86727b2 100755 --- a/setup.py +++ b/setup.py @@ -183,7 +183,8 @@ else: [f for f in glob('doc/examples/*') if is_f(f)]), (USR + '/share/doc/cloud-init/examples/seed', [f for f in glob('doc/examples/seed/*') if is_f(f)]), - (LIB + '/udev/rules.d', ['udev/66-azure-ephemeral.rules']), + (LIB + '/udev/rules.d', [f for f in glob('udev/*.rules')]), + (LIB + '/udev', ['udev/cloud-init-wait']), ] # Use a subclass for install that handles # adding on the right init system configuration files diff --git a/systemd/cloud-init-generator b/systemd/cloud-init-generator index 2d319695..ae286d58 100755 --- a/systemd/cloud-init-generator +++ b/systemd/cloud-init-generator @@ -107,6 +107,9 @@ main() { "ln $CLOUD_SYSTEM_TARGET $link_path" fi fi + # this touches /run/cloud-init/enabled, which is read by + # udev/cloud-init-wait. If not present, it will exit quickly. + touch "$LOG_D/$ENABLE" elif [ "$result" = "$DISABLE" ]; then if [ -f "$link_path" ]; then if rm -f "$link_path"; then diff --git a/udev/79-cloud-init-net-setup-link.rules b/udev/79-cloud-init-net-setup-link.rules deleted file mode 100644 index 03dba382..00000000 --- a/udev/79-cloud-init-net-setup-link.rules +++ /dev/null @@ -1,18 +0,0 @@ -# cloud-init rules to apply - -SUBSYSTEM!="net", GOTO="cloudinit_naming_end" - -IMPORT{builtin}="path_id" - -ACTION!="add", GOTO="cloudinit_naming_end" - -# net_setup_link provides us with systemd names for reference -IMPORT{builtin}="net_setup_link" -ATTR{address}!="", ENV{MAC_ADDRESS}="$attr{address}" -IMPORT{program}="/lib/udev/cloud-init-name-device" - -ENV{CLOUDINIT_NET_NAME}!="", NAME="$env{CLOUDINIT_NET_NAME}" - -LABEL="cloudinit_naming_end" - -# vi: ts=4 expandtab syntax=udevrules diff --git a/udev/79-cloud-init-net-wait.rules b/udev/79-cloud-init-net-wait.rules new file mode 100644 index 00000000..8344222a --- /dev/null +++ b/udev/79-cloud-init-net-wait.rules @@ -0,0 +1,10 @@ +# cloud-init cold/hot-plug blocking mechanism +# this file blocks further processing of network events +# until cloud-init local has had a chance to read and apply network +SUBSYSTEM!="net", GOTO="cloudinit_naming_end" +ACTION!="add", GOTO="cloudinit_naming_end" + +IMPORT{program}="/lib/udev/cloud-init-wait" + +LABEL="cloudinit_naming_end" +# vi: ts=4 expandtab syntax=udevrules diff --git a/udev/cloud-init-wait b/udev/cloud-init-wait new file mode 100755 index 00000000..345333f9 --- /dev/null +++ b/udev/cloud-init-wait @@ -0,0 +1,82 @@ +#!/bin/sh + +CI_NET_READY="/run/cloud-init/network-config-ready" +LOG="/run/cloud-init/${0##*/}.log" +LOG_INIT=0 +DEBUG=0 + +find_name() { + local match="" name="" none="_UNSET" pound="#" + while read match name; do + [ "${match#${pound}}" = "$match" ] || continue + case "$match" in + ID_NET_NAME=${ID_NET_NAME:-$none}) _RET="$name"; return 0;; + ID_NET_NAME_PATH=${ID_NET_NAME_PATH:-$none}) _RET="$name"; return 0;; + MAC_ADDRESS=${MAC_ADDRESS:-$none}) _RET="$name"; return 0;; + INTERFACE=${INTERFACE:-$none}) _RET="$name"; return 0;; + esac + done + return 0 +} + +block_until_ready() { + local fname="$1" + local naplen="$2" max="$3" n=0 + while ! [ -f "$fname" ]; do + n=$(($n+1)) + [ "$n" -ge "$max" ] && return 1 + sleep $naplen + done +} + +log() { + [ -n "${LOG}" ] || return + [ "${DEBUG:-0}" = "0" ] && return + + if [ $LOG_INIT = 0 ]; then + if [ -d "${LOG%/*}" ] || mkdir -p "${LOG%/*}"; then + LOG_INIT=1 + else + echo "${0##*/}: WARN: log init to ${LOG%/*}" 1>&2 + return + fi + elif [ "$LOG_INIT" = "-1" ]; then + return + fi + local info="$$ $INTERFACE" + if [ "$DEBUG" -gt 1 ]; then + local up idle + read up idle < /proc/uptime + info="$$ $INTERFACE $up" + fi + echo "[$info]" "$@" >> "$LOG" +} + +main() { + local name="" readyfile="$CI_NET_READY" + local info="INTERFACE=${INTERFACE} ID_NET_NAME=${ID_NET_NAME}" + info="$info ID_NET_NAME_PATH=${ID_NET_NAME_PATH}" + info="$info MAC_ADDRESS=${MAC_ADDRESS}" + log "$info" + + ## Check to see if cloud-init.target is set. If cloud-init is + ## disabled we do not want to do anything. + if [ ! -f "/run/cloud-init/enabled" ]; then + log "cloud-init disabled" + return 0 + fi + + block_until_ready "$readyfile" .1 600 || + { log "failed waiting for ready on $INTERFACE"; return 1; } + + #find_name < "$CI_NET_RULES" && name="$_RET" || + # { log "failed to find match for $INTERFACE"; return 0; } + + log "net config ready" + #[ -z "$name" ] || echo "CLOUDINIT_NET_NAME=$name" +} + +main "$@" +exit + +# vi: ts=4 expandtab -- cgit v1.2.3 From db54b59b90c8db2fc4a637ae09d3f0df14e77acb Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 18 Mar 2016 20:42:49 -0400 Subject: remove the 'find_name' function that was here. I had left this in to commit it, it was my first pass at cloud-init doing the naming itself. That design was then replaced with the idea for cloud-init to instead write systemd.rules files. --- udev/cloud-init-wait | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'udev') diff --git a/udev/cloud-init-wait b/udev/cloud-init-wait index 345333f9..f27309e3 100755 --- a/udev/cloud-init-wait +++ b/udev/cloud-init-wait @@ -5,20 +5,6 @@ LOG="/run/cloud-init/${0##*/}.log" LOG_INIT=0 DEBUG=0 -find_name() { - local match="" name="" none="_UNSET" pound="#" - while read match name; do - [ "${match#${pound}}" = "$match" ] || continue - case "$match" in - ID_NET_NAME=${ID_NET_NAME:-$none}) _RET="$name"; return 0;; - ID_NET_NAME_PATH=${ID_NET_NAME_PATH:-$none}) _RET="$name"; return 0;; - MAC_ADDRESS=${MAC_ADDRESS:-$none}) _RET="$name"; return 0;; - INTERFACE=${INTERFACE:-$none}) _RET="$name"; return 0;; - esac - done - return 0 -} - block_until_ready() { local fname="$1" local naplen="$2" max="$3" n=0 @@ -69,11 +55,7 @@ main() { block_until_ready "$readyfile" .1 600 || { log "failed waiting for ready on $INTERFACE"; return 1; } - #find_name < "$CI_NET_RULES" && name="$_RET" || - # { log "failed to find match for $INTERFACE"; return 0; } - log "net config ready" - #[ -z "$name" ] || echo "CLOUDINIT_NET_NAME=$name" } main "$@" -- cgit v1.2.3 From 16751f75a51814e4873199eddec15040dd221561 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Sun, 20 Mar 2016 22:31:21 -0400 Subject: fix creation of network-config-ready and dont bother waiting on lo --- systemd/cloud-init-local.service | 4 +--- udev/cloud-init-wait | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'udev') diff --git a/systemd/cloud-init-local.service b/systemd/cloud-init-local.service index f3a92e2f..dd737644 100644 --- a/systemd/cloud-init-local.service +++ b/systemd/cloud-init-local.service @@ -10,9 +10,7 @@ Before=shutdown.target [Service] Type=oneshot ExecStart=/usr/bin/cloud-init init --local -## FIXME: remove this when cloud-initn local does it itself -## or otherwise better signals any blocking udev events -ExecStopPost=touch /run/cloud-init/network-config-ready +ExecStart=/bin/touch /run/cloud-init/network-config-ready RemainAfterExit=yes TimeoutSec=0 diff --git a/udev/cloud-init-wait b/udev/cloud-init-wait index f27309e3..7d53dee4 100755 --- a/udev/cloud-init-wait +++ b/udev/cloud-init-wait @@ -52,6 +52,10 @@ main() { return 0 fi + if [ "${INTERFACE#lo}" != "$INTERFACE" ]; then + return 0 + fi + block_until_ready "$readyfile" .1 600 || { log "failed waiting for ready on $INTERFACE"; return 1; } -- cgit v1.2.3