added more config options, among others an option to run depclean on
gentoo
This commit is contained in:
parent
3f9103552e
commit
b60d5a4e5c
16
bin/sau
16
bin/sau
@ -40,6 +40,16 @@ def main():
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
os.system('/sbin/reboot')
|
os.system('/sbin/reboot')
|
||||||
|
|
||||||
|
def _conf_level_to_logging_level(conf_level):
|
||||||
|
if conf_level.lower() == 'debug':
|
||||||
|
return logging.DEBUG
|
||||||
|
if conf_level.lower() == 'info':
|
||||||
|
return logging.INFO
|
||||||
|
if conf_level.lower() == 'warning':
|
||||||
|
return logging.WARNING
|
||||||
|
if conf_level.lower() == 'error':
|
||||||
|
return logging.error
|
||||||
|
return logging.DEBUG
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sau.config = configparser.SafeConfigParser()
|
sau.config = configparser.SafeConfigParser()
|
||||||
@ -58,16 +68,18 @@ if __name__ == '__main__':
|
|||||||
log = logging.getLogger(sau.LOGNAME)
|
log = logging.getLogger(sau.LOGNAME)
|
||||||
log.setLevel(logging.DEBUG)
|
log.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
conf_level = _conf_level_to_logging_level(conf.get('default', 'stderr_loglevel', fallback="debug"))
|
||||||
handler = logging.StreamHandler()
|
handler = logging.StreamHandler()
|
||||||
formatter = logging.Formatter(fmt='%(asctime)s %(levelname)s: %(message)s')
|
formatter = logging.Formatter(fmt='%(asctime)s %(levelname)s: %(message)s')
|
||||||
handler.setFormatter(formatter)
|
handler.setFormatter(formatter)
|
||||||
handler.setLevel(logging.DEBUG)
|
handler.setLevel(conf_level)
|
||||||
log.addHandler(handler)
|
log.addHandler(handler)
|
||||||
|
|
||||||
|
|
||||||
|
conf_level = _conf_level_to_logging_level(conf.get('default', 'syslog_loglevel', fallback="debug"))
|
||||||
handler = logging.handlers.SysLogHandler(address=syslog_socket)
|
handler = logging.handlers.SysLogHandler(address=syslog_socket)
|
||||||
formatter = logging.Formatter(fmt='{}[%(process)s] %(message)s'.format(sau.LOGNAME))
|
formatter = logging.Formatter(fmt='{}[%(process)s] %(message)s'.format(sau.LOGNAME))
|
||||||
handler.setFormatter(formatter)
|
handler.setFormatter(formatter)
|
||||||
handler.setLevel(logging.INFO)
|
handler.setLevel(conf_level)
|
||||||
log.addHandler(handler)
|
log.addHandler(handler)
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
13
config.cfg
13
config.cfg
@ -16,10 +16,23 @@ min_version_diff=2
|
|||||||
# not close all deleted files (any platform)
|
# not close all deleted files (any platform)
|
||||||
do_reboot=no
|
do_reboot=no
|
||||||
|
|
||||||
|
# FreeBSD system update (freebsd-update fetch install, not freebsd-update upgrade)
|
||||||
do_system_upgrade=yes
|
do_system_upgrade=yes
|
||||||
|
|
||||||
|
# upgrade packages
|
||||||
do_package_upgrade=yes
|
do_package_upgrade=yes
|
||||||
|
|
||||||
|
# restart services affected by previous upgrades
|
||||||
do_service_restart=yes
|
do_service_restart=yes
|
||||||
|
|
||||||
|
# do depclean on Gentoo
|
||||||
|
do_depclean=yes
|
||||||
|
|
||||||
|
# to only write to stderr when something unexpected happens or manual action is required
|
||||||
|
# set stderr_loglevel to warning
|
||||||
|
stderr_loglevel=debug
|
||||||
|
syslog_loglevel=info
|
||||||
|
|
||||||
|
|
||||||
# The packages section contains <package>=<version_diff> pairs to override the
|
# The packages section contains <package>=<version_diff> pairs to override the
|
||||||
# default min_version_diff. Note that package naming may differ depending on
|
# default min_version_diff. Note that package naming may differ depending on
|
||||||
|
@ -255,3 +255,25 @@ def pkg_upgrade():
|
|||||||
for line in out.splitlines():
|
for line in out.splitlines():
|
||||||
if line.startswith(' * '):
|
if line.startswith(' * '):
|
||||||
log.warning(line)
|
log.warning(line)
|
||||||
|
|
||||||
|
if conf.getboolean('default', 'do_depclean', fallback=False):
|
||||||
|
cmd = [ EMERGE_PATH, '--color', 'n', '-q', '--depclean' ]
|
||||||
|
log.debug('Executing "{}"'.format(' '.join(cmd)))
|
||||||
|
proc = subprocess.Popen(
|
||||||
|
cmd,
|
||||||
|
stdout = subprocess.PIPE,
|
||||||
|
stderr = subprocess.PIPE)
|
||||||
|
out, err = proc.communicate()
|
||||||
|
out = out.decode('utf-8')
|
||||||
|
err = err.decode('utf-8')
|
||||||
|
if proc.returncode != 0 or err:
|
||||||
|
log.error('depclean returned {}'.format(proc.returncode))
|
||||||
|
for line in out.splitlines():
|
||||||
|
log.error('stdout: {}'.format(line))
|
||||||
|
for line in err.splitlines():
|
||||||
|
log.error('stderr: {}'.format(line))
|
||||||
|
else:
|
||||||
|
log.info('depclean complete')
|
||||||
|
for line in out.splitlines():
|
||||||
|
if line.startswith(' * '):
|
||||||
|
log.warning(line)
|
||||||
|
Loading…
Reference in New Issue
Block a user