summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2013-09-25 14:52:55 -0400
committerScott Moser <smoser@ubuntu.com>2013-09-25 14:52:55 -0400
commit9e5fd8410033bce66e4eaa2b51e29801c8327519 (patch)
tree9bfd20e85b4d6cf33ea3dad754aa9e35d42a020f /cloudinit/util.py
parent3bebad68b627595652eabc9e7222b69197180622 (diff)
parentf0e1bf38a2b943d27c8fe20724799b2e552e7adc (diff)
downloadvyos-cloud-init-9e5fd8410033bce66e4eaa2b51e29801c8327519.tar.gz
vyos-cloud-init-9e5fd8410033bce66e4eaa2b51e29801c8327519.zip
multi_log: only write to /dev/console if it exists.
Some containers lack /dev/console, so when multi_log attempts to open that device and write to it directly things can start going haywire. Here we address this problem by sending console-bound output to stdout and letting init take care of getting it to the console instead. We already configure upstart with "console output", so we need only change systemd to use "journal+console". The one reason that 'console output' might not be sufficient is if the user redirected output with 'output'. Ie: output: init: "> /var/log/my-cloud-init.log" Would then mean all output would go there, and anything that *needed* to go to the console (and was explicitly using multi_log for that purpose) would not get there.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index deac8c8d..cd1cc1a4 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -360,11 +360,21 @@ def multi_log(text, console=True, stderr=True,
if stderr:
sys.stderr.write(text)
if console:
- # Don't use the write_file since
- # this might be 'sensitive' info (not debug worthy?)
- with open('/dev/console', 'wb') as wfh:
- wfh.write(text)
- wfh.flush()
+ conpath = "/dev/console"
+ if os.path.exists(conpath):
+ with open(conpath, 'wb') as wfh:
+ wfh.write(text)
+ wfh.flush()
+ else:
+ # A container may lack /dev/console (arguably a container bug). If
+ # it does not exist, then write output to stdout. this will result
+ # in duplicate stderr and stdout messages if stderr was True.
+ #
+ # even though upstart or systemd might have set up output to go to
+ # /dev/console, the user may have configured elsewhere via
+ # cloud-config 'output'. If there is /dev/console, messages will
+ # still get there.
+ sys.stdout.write(text)
if log:
if text[-1] == "\n":
log.log(log_level, text[:-1])