improve startup if no eth0 is available (LP: #714807)

This commit is contained in:
Scott Moser 2011-02-18 15:12:04 -05:00
parent 28ffcfc820
commit b26c4ddb15
4 changed files with 56 additions and 12 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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

View File

@ -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