From 67bf7722398278e7089098dfd683389ef4e418c5 Mon Sep 17 00:00:00 2001
From: Scott Moser <smoser@ubuntu.com>
Date: Thu, 13 Sep 2012 14:01:04 -0400
Subject: add cloud-init-container.conf

This changes the way that we avoid cloud-init-nonet hanging in a container.
Previously, under LP: #800824 we tried 'start networking', but that caused
issues described in LP: #1031065.

Here, we emit the net-device-added for any devices that have not yet been
seen.

LP: #1031065
---
 upstart/cloud-init-container.conf | 41 +++++++++++++++++++++++++++++++++++++++
 upstart/cloud-init-nonet.conf     |  2 --
 2 files changed, 41 insertions(+), 2 deletions(-)
 create mode 100644 upstart/cloud-init-container.conf

(limited to 'upstart')

diff --git a/upstart/cloud-init-container.conf b/upstart/cloud-init-container.conf
new file mode 100644
index 00000000..b3123721
--- /dev/null
+++ b/upstart/cloud-init-container.conf
@@ -0,0 +1,41 @@
+# in a lxc container, events for network interfaces do not
+# get created or may be missed.  This helps cloud-init-nonet along
+# by emitting those events if they have not been emitted.
+
+start on container
+stop on static-network-up
+task
+
+emits net-device-added
+
+console output
+
+script
+   # if we are inside a container, then we may have to emit the ifup
+   # events for 'auto' network devices.
+   set -f
+
+   # from /etc/network/if-up.d/upstart
+   MARK_DEV_PREFIX="/run/network/ifup."
+   MARK_STATIC_NETWORK_EMITTED="/run/network/static-network-up-emitted"
+   # if the all static network interfaces are already up, nothing to do
+   [ -f "$MARK_STATIC_NETWORK_EMITTED" ] && exit 0
+
+   # get list of all 'auto' interfaces. if there are none, nothing to do.
+   auto_list=$(ifquery --list --allow auto 2>/dev/null) || :
+   [ -z "$auto_list" ] && exit 0
+   set -- ${auto_list}
+   [ "$*" = "lo" ] && exit 0
+
+   to_emit=""
+   for iface in "$@"; do
+      [ "$iface" = "lo" ] && continue
+      # skip interfaces that are already up
+      [ -f "${MARK_DEV_PREFIX}${iface}" ] && continue
+      initctl emit --no-wait net-device-added "INTERFACE=$iface" &&
+         emitted="${emitted} ${iface}" || :
+   done
+
+   [ -z "${emitted# }" ] ||
+      echo "${UPSTART_JOB}: emitted ifup for ${emitted# }"
+end script
diff --git a/upstart/cloud-init-nonet.conf b/upstart/cloud-init-nonet.conf
index 7b69e584..118ffc1c 100644
--- a/upstart/cloud-init-nonet.conf
+++ b/upstart/cloud-init-nonet.conf
@@ -18,8 +18,6 @@ script
 
    [ -f /var/lib/cloud/instance/obj.pkl ] && exit 0
 
-   start networking >/dev/null
-
    short=10; long=120;
    sleep ${short}
    echo $UPSTART_JOB "waiting ${long} seconds for a network device."
-- 
cgit v1.2.3


From d2f00fd2af9417a91c78e9cab5747cd6e218aa39 Mon Sep 17 00:00:00 2001
From: Scott Moser <smoser@ubuntu.com>
Date: Thu, 13 Sep 2012 20:02:37 -0400
Subject: only emit if there is a device present.

---
 upstart/cloud-init-container.conf | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

(limited to 'upstart')

diff --git a/upstart/cloud-init-container.conf b/upstart/cloud-init-container.conf
index b3123721..497e75c8 100644
--- a/upstart/cloud-init-container.conf
+++ b/upstart/cloud-init-container.conf
@@ -27,13 +27,23 @@ script
    set -- ${auto_list}
    [ "$*" = "lo" ] && exit 0
 
-   to_emit=""
+   # we only want to emit for interfaces that do not exist, so filter
+   # out anything that does not exist.
    for iface in "$@"; do
       [ "$iface" = "lo" ] && continue
       # skip interfaces that are already up
       [ -f "${MARK_DEV_PREFIX}${iface}" ] && continue
+
+      if [ -d /sys/net ]; then
+         # if /sys is mounted, and there is no /sys/net/iface, then no device
+         [ -e "/sys/net/$iface" ] && continue
+      else
+         # sys wasn't mounted, so just check via 'ifconfig'
+         ifconfig "$iface" >/dev/null 2>&1 || continue
+      fi 
       initctl emit --no-wait net-device-added "INTERFACE=$iface" &&
-         emitted="${emitted} ${iface}" || :
+         emitted="$emitted $iface" ||
+         echo "warn: ${UPSTART_JOB} failed to emit net-device-added INTERFACE=$iface"
    done
 
    [ -z "${emitted# }" ] ||
-- 
cgit v1.2.3


From 18cbd9ae7872f83b4eaccdbdf2cf5023b92d7812 Mon Sep 17 00:00:00 2001
From: Scott Moser <smoser@ubuntu.com>
Date: Thu, 13 Sep 2012 20:07:18 -0400
Subject: remove trailing whitespace

---
 upstart/cloud-init-container.conf | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'upstart')

diff --git a/upstart/cloud-init-container.conf b/upstart/cloud-init-container.conf
index 497e75c8..051c6e50 100644
--- a/upstart/cloud-init-container.conf
+++ b/upstart/cloud-init-container.conf
@@ -40,7 +40,7 @@ script
       else
          # sys wasn't mounted, so just check via 'ifconfig'
          ifconfig "$iface" >/dev/null 2>&1 || continue
-      fi 
+      fi
       initctl emit --no-wait net-device-added "INTERFACE=$iface" &&
          emitted="$emitted $iface" ||
          echo "warn: ${UPSTART_JOB} failed to emit net-device-added INTERFACE=$iface"
-- 
cgit v1.2.3