summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rwxr-xr-xcloud-init.py42
-rw-r--r--upstart/cloud-init-nonet.conf22
-rw-r--r--upstart/cloud-init.conf3
4 files changed, 56 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 782750fe..01282954 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -21,6 +21,7 @@
'#opt_include <filename>' or '#include <filename>' in cloud.cfg
- allow /etc/hosts to be written from hosts.tmpl. which allows
getting local-hostname into /etc/hosts (LP: #720440)
+ - better handle startup if there is no eth0 (LP: #714807)
0.6.0:
- change permissions of /var/log/cloud-init.log to accomodate
syslog writing to it (LP: #704509)
diff --git a/cloud-init.py b/cloud-init.py
index e8454eaa..3c9df13e 100755
--- a/cloud-init.py
+++ b/cloud-init.py
@@ -27,6 +27,7 @@ import cloudinit.DataSource as ds
import time
import logging
import errno
+import os
def warn(wstr):
sys.stderr.write("WARN:%s" % wstr)
@@ -75,29 +76,50 @@ def main():
except Exception as e:
warn("Failed to get and set output config: %s\n" % e)
- msg = "cloud-init %s running: %s. up %s seconds" % (cmd, now, uptime)
- sys.stderr.write(msg + "\n")
- sys.stderr.flush()
-
cloudinit.logging_set_from_cfg(cfg)
log = logging.getLogger()
- log.info(msg)
try:
cloudinit.initfs()
except Exception as e:
warn("failed to initfs, likely bad things to come: %s\n" % str(e))
-
- # cache is not instance specific, so it has to be purged
- # but we want 'start' to benefit from a cache if
- # a previous start-local populated one
- if cmd == "start-local":
+ nonet_path = "%s/%s" % (cloudinit.get_cpath("data"), "no-net")
+
+ if cmd == "start":
+ stop_files = ( cloudinit.get_ipath_cur("obj_pkl"), nonet_path )
+ # if starting as the network start, there are cases
+ # where everything is already done for us, and it makes
+ # most sense to exit early and silently
+ for f in stop_files:
+ try:
+ fp = open("/var/lib/cloud/instance/obj.pkl","r")
+ fp.close()
+ except:
+ continue
+
+ log.debug("no need for cloud-init start to run (%s)\n", f)
+ sys.exit(0)
+ elif cmd == "start-local":
+ # cache is not instance specific, so it has to be purged
+ # but we want 'start' to benefit from a cache if
+ # a previous start-local populated one
manclean = util.get_cfg_option_bool(cfg, 'manual_cache_clean',False)
if manclean:
log.debug("not purging cache, manual_cache_clean = True")
cloudinit.purge_cache(not manclean)
+ try:
+ os.unlink(nonet_path)
+ except OSError as e:
+ if e.errno != errno.ENOENT: raise
+
+ msg = "cloud-init %s running: %s. up %s seconds" % (cmd, now, uptime)
+ sys.stderr.write(msg + "\n")
+ sys.stderr.flush()
+
+ log.info(msg)
+
cloud = cloudinit.CloudInit(ds_deps=deps[cmd])
try:
diff --git a/upstart/cloud-init-nonet.conf b/upstart/cloud-init-nonet.conf
new file mode 100644
index 00000000..2ac98286
--- /dev/null
+++ b/upstart/cloud-init-nonet.conf
@@ -0,0 +1,22 @@
+# cloud-init-no-net
+# the purpose of this job is
+# * to block running of cloud-init until a non 'lo' interface is up
+# * timeout if one doens't come up in a reasonable amount of time
+start on mounted MOUNTPOINT=/ and stopped cloud-init-local
+stop on net-device-up IFACE!=lo
+task
+
+console output
+
+script
+ # if a non 'lo' interface is up, exit immediately
+ grep -qv '^lo' /var/run/network/ifstate && exit 0
+
+ [ -f /var/lib/cloud/instance/obj.pkl ] && exit 0
+ sleep 10
+ echo $UPSTART_JOB "waiting for a network device."
+ sleep 60
+ echo $UPSTART_JOB "gave up waiting for a network device."
+ : > /var/lib/cloud/data/no-net
+end script
+# EOF
diff --git a/upstart/cloud-init.conf b/upstart/cloud-init.conf
index cb2b437b..b9be5981 100644
--- a/upstart/cloud-init.conf
+++ b/upstart/cloud-init.conf
@@ -1,7 +1,6 @@
# cloud-init - the initial cloud-init job
# crawls metadata service, emits cloud-config
-start on (mounted MOUNTPOINT=/ and net-device-up IFACE=eth0 and \
- stopped cloud-init-local )
+start on mounted MOUNTPOINT=/ and stopped cloud-init-nonet
task