diff --git a/sau/platforms.py b/sau/platforms.py index b664396..8ddc889 100644 --- a/sau/platforms.py +++ b/sau/platforms.py @@ -1,3 +1,4 @@ +import os import platform import sau.errors @@ -9,9 +10,10 @@ def get_platform(): if platform.system() == 'FreeBSD': platform_mod = sau.freebsd elif platform.system() == 'Linux': - if 'gentoo' in platform.release(): + if os.path.exists('/usr/bin/emerge'): platform_mod = sau.gentoo + if not platform_mod: raise sau.errors.PlatformNotSupported("System: {} Release: {} Version: {} is not supported".format( platform.system(), diff --git a/sau/services.py b/sau/services.py index b14c771..ae22395 100644 --- a/sau/services.py +++ b/sau/services.py @@ -12,6 +12,10 @@ import sau.platforms proc_fd_map_re = re.compile(r'^.*(/[^\(]*) \(deleted\)$') +def _warn(policy, msg): + if not policy.startswith('silent'): + log.warning(msg) + def _get_deleted_open_files(proc): log = logging.getLogger(sau.LOGNAME) files = set() @@ -117,11 +121,10 @@ def restart_services(): elif policy == 'warn': log.warning('Service "{}" has open deleted files and should be restarted'.format(service)) continue - elif policy == 'reboot': - log.warning('Rebooting because {} has opened files'.format(service)) + elif 'reboot' in policy: + _warn('Rebooting because {} has opened files'.format(service)) recommend_restart = True - if not ( policy.startswith('silent') or policy == 'reboot' ): - log.warning('Restarting service {}'.format(service)) + _warn('Restarting service {}'.format(service)) platform.restart_service(service) tested_parents = set() @@ -137,14 +140,15 @@ def restart_services(): if _get_deleted_open_files(proc): tested_parents.add(parent) service = _get_service_from_proc(parent) + policy = _get_service_restart_policy(service) if not service: - log.warning('could not re-check process {} - failed to identify service'.format(proc)) + _warn('could not re-check process {} - failed to identify service'.format(proc)) recommend_restart = True continue log.debug('{} is in service {}'.format(proc, service)) if parent_name in services and not services[parent_name]: - log.warning('{} (parent {}) does not belong to a service and could not be restarted'.format(proc, parent)) + _warn('{} (parent {}) does not belong to a service and could not be restarted'.format(proc, parent)) recommend_restart = True continue elif parent_name in services: @@ -152,7 +156,7 @@ def restart_services(): log.debug('service {} has policy {}'.format(service, policy)) if policy in ('ignore', 'warn'): continue - log.warning('{} (parent {}) still has deleted files open'.format(proc, parent)) + _warn('{} (parent {}) still has deleted files open'.format(proc, parent)) recommend_restart = True return recommend_restart @@ -160,7 +164,7 @@ def _get_service_restart_policy(service): log = logging.getLogger(sau.LOGNAME) conf = sau.config policy = conf.get('services', service, fallback=None) - if policy and policy.lower() in ('restart', 'warn', 'ignore', 'silent-restart', 'reboot'): + if policy and policy.lower() in ('restart', 'warn', 'ignore', 'silent-restart', 'silent-reboot'): return policy.lower() elif policy: log.warning('service policy {} for {} is invalid'.format(policy, service))