diff options
author | Scott Moser <smoser@ubuntu.com> | 2016-03-29 09:11:25 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2016-03-29 09:11:25 -0400 |
commit | 78c9de871eb2a68da36fb4397fe756b88dc9eb15 (patch) | |
tree | cd7814ae943f5f1da557272f634874439cdbac52 | |
parent | 18bf614ca1d9fbabdf83495e7675a2cacaf6c2f4 (diff) | |
parent | bf88c6ef54608f4488fca806b5f30afad08d6c51 (diff) | |
download | vyos-cloud-init-78c9de871eb2a68da36fb4397fe756b88dc9eb15.tar.gz vyos-cloud-init-78c9de871eb2a68da36fb4397fe756b88dc9eb15.zip |
improve how cloud-init-wait waits
Instead of sleep and check loop, use 'udevadm settle' to wait.
since we run from a udev event, this is sufficient.
udev settle will exit when either of
a.) the file exists
b.) the udev event queue has all been processed.
c.) timeout is reached.
Since cloud-init-wait is being run as a udev event, 'b' cannot
be satisfied until it finishes. Thus, this essentially becomes a
inotify based wait for the file /run/cloud-init/network-config-ready
and no loops are needed.
-rwxr-xr-x | udev/cloud-init-wait | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/udev/cloud-init-wait b/udev/cloud-init-wait index 7d53dee4..b434005d 100755 --- a/udev/cloud-init-wait +++ b/udev/cloud-init-wait @@ -3,16 +3,18 @@ CI_NET_READY="/run/cloud-init/network-config-ready" LOG="/run/cloud-init/${0##*/}.log" LOG_INIT=0 +MAX_WAIT=60 DEBUG=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 + local fname="$1" max="$2" + [ -f "$fname" ] && return 0 + # udevadm settle below will exit at the first of 3 conditions + # 1.) timeout 2.) file exists 3.) all in-flight udev events are processed + # since this is being run from a udev event, the 3 wont happen. + # thus, this is essentially a inotify wait or timeout on a file in /run + # that is created by cloud-init-local. + udevadm settle "--timeout=$max" "--exit-if-exists=$fname" } log() { @@ -56,7 +58,7 @@ main() { return 0 fi - block_until_ready "$readyfile" .1 600 || + block_until_ready "$readyfile" "$MAX_WAIT" || { log "failed waiting for ready on $INTERFACE"; return 1; } log "net config ready" |