fix logging perms with list rather than single
This commit is contained in:
parent
ddb9e74042
commit
502a896dd6
@ -47,7 +47,7 @@ CFG_BUILTIN = {
|
|||||||
],
|
],
|
||||||
'def_log_file': '/var/log/cloud-init.log',
|
'def_log_file': '/var/log/cloud-init.log',
|
||||||
'log_cfgs': [],
|
'log_cfgs': [],
|
||||||
'syslog_fix_perms': 'syslog:adm',
|
'syslog_fix_perms': ['syslog:adm', 'root:adm'],
|
||||||
'system_info': {
|
'system_info': {
|
||||||
'paths': {
|
'paths': {
|
||||||
'cloud_dir': '/var/lib/cloud',
|
'cloud_dir': '/var/lib/cloud',
|
||||||
|
@ -148,16 +148,25 @@ class Init(object):
|
|||||||
def _initialize_filesystem(self):
|
def _initialize_filesystem(self):
|
||||||
util.ensure_dirs(self._initial_subdirs())
|
util.ensure_dirs(self._initial_subdirs())
|
||||||
log_file = util.get_cfg_option_str(self.cfg, 'def_log_file')
|
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:
|
if log_file:
|
||||||
util.ensure_file(log_file)
|
util.ensure_file(log_file)
|
||||||
if perms:
|
perms = self.cfg.get('syslog_fix_perms')
|
||||||
u, g = util.extract_usergroup(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:
|
try:
|
||||||
util.chownbyname(log_file, u, g)
|
util.chownbyname(log_file, u, g)
|
||||||
except OSError:
|
return
|
||||||
util.logexc(LOG, "Unable to change the ownership of %s to "
|
except OSError as e:
|
||||||
"user %s, group %s", log_file, u, g)
|
error = e
|
||||||
|
|
||||||
|
LOG.warn("Failed changing perms on '%s'. tried: %s. %s",
|
||||||
|
log_file, ','.join(perms), error)
|
||||||
|
|
||||||
def read_cfg(self, extra_fns=None):
|
def read_cfg(self, extra_fns=None):
|
||||||
# None check so that we don't keep on re-loading if empty
|
# None check so that we don't keep on re-loading if empty
|
||||||
|
@ -536,6 +536,8 @@ timezone: US/Eastern
|
|||||||
#
|
#
|
||||||
# to remedy this situation, 'def_log_file' can be set to a filename
|
# to remedy this situation, 'def_log_file' can be set to a filename
|
||||||
# and syslog_fix_perms to a string containing "<user>:<group>"
|
# 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 default values are '/var/log/cloud-init.log' and 'syslog:adm'
|
||||||
# the value of 'def_log_file' should match what is configured in logging
|
# the value of 'def_log_file' should match what is configured in logging
|
||||||
|
Loading…
x
Reference in New Issue
Block a user