summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2012-07-10 17:47:02 -0400
committerScott Moser <smoser@ubuntu.com>2012-07-10 17:47:02 -0400
commite119877fcf9c38a89c4a054b146d8189b866d4e8 (patch)
treee62eeff323e8c60ce1b41f9a2f3da32dfa63f5ed /bin
parentfa09651fcea222d661803b6a86a79fbf6f147374 (diff)
downloadvyos-cloud-init-e119877fcf9c38a89c4a054b146d8189b866d4e8.tar.gz
vyos-cloud-init-e119877fcf9c38a89c4a054b146d8189b866d4e8.zip
send welcome message after logging has been applied
in the 'cloud-init init' stages, we want the welcome message to get to the correct output as specified by the system's configuration. Ie, if the local /etc/cloud.config.d had 'output' or 'log_cfg' settings we want those to be able to affect the welcome message also. In normal operation, nothing else will go to stdout or stderr before this, and likely/hopefully nothing terribly important to the logs.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/cloud-init34
1 files changed, 27 insertions, 7 deletions
diff --git a/bin/cloud-init b/bin/cloud-init
index 51360270..9dd7296e 100755
--- a/bin/cloud-init
+++ b/bin/cloud-init
@@ -82,16 +82,22 @@ def print_exc(msg=''):
sys.stderr.write("\n")
-def welcome(action):
+def welcome(action, msg=None):
+ if not msg:
+ msg = welcome_format(action)
+ util.multi_log("%s\n" % (msg),
+ console=False, stderr=True, log=LOG)
+ return msg
+
+
+def welcome_format(action):
tpl_params = {
'version': version.version_string(),
'uptime': util.uptime(),
'timestamp': util.time_rfc2822(),
'action': action,
}
- tpl_msg = templater.render_string(WELCOME_MSG_TPL, tpl_params)
- util.multi_log("%s\n" % (tpl_msg),
- console=False, stderr=True)
+ return templater.render_string(WELCOME_MSG_TPL, tpl_params)
def extract_fns(args):
@@ -154,7 +160,7 @@ def main_init(name, args):
# the modules objects configuration
# 10. Run the modules for the 'init' stage
# 11. Done!
- welcome(name)
+ w_msg = welcome_format(name)
init = stages.Init(deps)
# Stage 1
init.read_cfg(extract_fns(args))
@@ -174,6 +180,12 @@ def main_init(name, args):
" longer be active shortly"))
logging.resetLogging()
logging.setupLogging(init.cfg)
+
+ # Any log usage prior to setupLogging above did not have local user log
+ # config applied. We send the welcome message now, as stderr/out have
+ # been redirected and log now configured.
+ welcome(name, msg=w_msg)
+
# Stage 3
try:
init.initialize()
@@ -284,7 +296,7 @@ def main_modules(action_name, args):
# the modules objects configuration
# 5. Run the modules for the given stage name
# 6. Done!
- welcome("%s:%s" % (action_name, name))
+ w_msg = welcome_format("%s:%s" % (action_name, name))
init = stages.Init(ds_deps=[])
# Stage 1
init.read_cfg(extract_fns(args))
@@ -316,6 +328,10 @@ def main_modules(action_name, args):
" longer be active shortly"))
logging.resetLogging()
logging.setupLogging(mods.cfg)
+
+ # now that logging is setup and stdout redirected, send welcome
+ welcome(name, msg=w_msg)
+
# Stage 5
return run_module_section(mods, name, name)
@@ -335,7 +351,7 @@ def main_single(name, args):
# 5. Run the single module
# 6. Done!
mod_name = args.name
- welcome("%s:%s" % (name, mod_name))
+ w_msg = welcome_format(name)
init = stages.Init(ds_deps=[])
# Stage 1
init.read_cfg(extract_fns(args))
@@ -374,6 +390,10 @@ def main_single(name, args):
" longer be active shortly"))
logging.resetLogging()
logging.setupLogging(mods.cfg)
+
+ # now that logging is setup and stdout redirected, send welcome
+ welcome(name, msg=w_msg)
+
# Stage 5
(which_ran, failures) = mods.run_single(mod_name,
mod_args,