fix logging perms with list rather than single

This commit is contained in:
Scott Moser 2015-03-04 12:42:34 -05:00
parent ddb9e74042
commit 502a896dd6
3 changed files with 18 additions and 7 deletions

View File

@ -47,7 +47,7 @@ CFG_BUILTIN = {
],
'def_log_file': '/var/log/cloud-init.log',
'log_cfgs': [],
'syslog_fix_perms': 'syslog:adm',
'syslog_fix_perms': ['syslog:adm', 'root:adm'],
'system_info': {
'paths': {
'cloud_dir': '/var/lib/cloud',

View File

@ -148,16 +148,25 @@ class Init(object):
def _initialize_filesystem(self):
util.ensure_dirs(self._initial_subdirs())
log_file = util.get_cfg_option_str(self.cfg, 'def_log_file')
perms = util.get_cfg_option_str(self.cfg, 'syslog_fix_perms')
if log_file:
util.ensure_file(log_file)
if perms:
u, g = util.extract_usergroup(perms)
perms = self.cfg.get('syslog_fix_perms')
if not perms:
perms = {}
if not isinstance(perms, list):
perms = [perms]
error = None
for perm in perms:
u, g = util.extract_usergroup(perm)
try:
util.chownbyname(log_file, u, g)
except OSError:
util.logexc(LOG, "Unable to change the ownership of %s to "
"user %s, group %s", log_file, u, g)
return
except OSError as e:
error = e
LOG.warn("Failed changing perms on '%s'. tried: %s. %s",
log_file, ','.join(perms), error)
def read_cfg(self, extra_fns=None):
# None check so that we don't keep on re-loading if empty

View File

@ -536,6 +536,8 @@ timezone: US/Eastern
#
# to remedy this situation, 'def_log_file' can be set to a filename
# and syslog_fix_perms to a string containing "<user>:<group>"
# if syslog_fix_perms is a list, it will iterate through and use the
# first pair that does not raise error.
#
# the default values are '/var/log/cloud-init.log' and 'syslog:adm'
# the value of 'def_log_file' should match what is configured in logging