summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2013-09-25 14:52:30 -0400
committerScott Moser <smoser@ubuntu.com>2013-09-25 14:52:30 -0400
commitf0e1bf38a2b943d27c8fe20724799b2e552e7adc (patch)
tree1a046548c0bd7b4f0c6b86a9049dc5ea6153e998
parent8827040ad3fdb951a38e39f73cf11fd73b17873f (diff)
downloadvyos-cloud-init-f0e1bf38a2b943d27c8fe20724799b2e552e7adc.tar.gz
vyos-cloud-init-f0e1bf38a2b943d27c8fe20724799b2e552e7adc.zip
instead of just writing to stdout, write to stdout if no /dev/console
-rw-r--r--cloudinit/util.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 02890448..89307aa5 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:
- # Some containers lack /dev/console, so we send output to
- # stdout and configure upstart with "console output" and
- # systemd with "journal+console" and let them take care of
- # getting output to the console.
- print text
+ 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])