diff options
-rw-r--r-- | cloudinit/config/cc_final_message.py | 2 | ||||
-rw-r--r-- | cloudinit/util.py | 20 | ||||
-rw-r--r-- | systemd/cloud-config.service | 2 | ||||
-rw-r--r-- | systemd/cloud-final.service | 2 | ||||
-rw-r--r-- | systemd/cloud-init-local.service | 2 | ||||
-rw-r--r-- | systemd/cloud-init.service | 2 |
6 files changed, 20 insertions, 10 deletions
diff --git a/cloudinit/config/cc_final_message.py b/cloudinit/config/cc_final_message.py index 6b864fda..e92cba4a 100644 --- a/cloudinit/config/cc_final_message.py +++ b/cloudinit/config/cc_final_message.py @@ -54,7 +54,7 @@ def handle(_name, cfg, cloud, log, args): 'datasource': str(cloud.datasource), } util.multi_log("%s\n" % (templater.render_string(msg_in, subs)), - console=False, stderr=True) + console=False, stderr=True, log=log) except Exception: util.logexc(log, "Failed to render final message template") 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]) diff --git a/systemd/cloud-config.service b/systemd/cloud-config.service index fc72fc48..41a86147 100644 --- a/systemd/cloud-config.service +++ b/systemd/cloud-config.service @@ -11,7 +11,7 @@ RemainAfterExit=yes TimeoutSec=0 # Output needs to appear in instance console output -StandardOutput=tty +StandardOutput=journal+console [Install] WantedBy=multi-user.target diff --git a/systemd/cloud-final.service b/systemd/cloud-final.service index f836eab6..ef0f52b9 100644 --- a/systemd/cloud-final.service +++ b/systemd/cloud-final.service @@ -11,7 +11,7 @@ RemainAfterExit=yes TimeoutSec=0 # Output needs to appear in instance console output -StandardOutput=tty +StandardOutput=journal+console [Install] WantedBy=multi-user.target diff --git a/systemd/cloud-init-local.service b/systemd/cloud-init-local.service index 6a551710..a31985c6 100644 --- a/systemd/cloud-init-local.service +++ b/systemd/cloud-init-local.service @@ -10,7 +10,7 @@ RemainAfterExit=yes TimeoutSec=0 # Output needs to appear in instance console output -StandardOutput=tty +StandardOutput=journal+console [Install] WantedBy=multi-user.target diff --git a/systemd/cloud-init.service b/systemd/cloud-init.service index d4eb9fa5..018a1fa8 100644 --- a/systemd/cloud-init.service +++ b/systemd/cloud-init.service @@ -11,7 +11,7 @@ RemainAfterExit=yes TimeoutSec=0 # Output needs to appear in instance console output -StandardOutput=tty +StandardOutput=journal+console [Install] WantedBy=multi-user.target |