diff --git a/config.cfg b/config.cfg index ad2af65..d9f93b0 100644 --- a/config.cfg +++ b/config.cfg @@ -64,7 +64,7 @@ qemu-system-x86_64= #ruby24=puppetserver puppetdb # The services section contains restart policy for specific services. -# valid policies are 'ignore', 'warn', 'restart' and 'silent-restart'. +# valid policies are 'ignore', 'warn', 'restart', 'silent-restart' and 'reboot'. # 'silent-restart' is like 'restart', but will not log a warning when # the service is restarted. [services] diff --git a/sau/services.py b/sau/services.py index 1ac370d..b14c771 100644 --- a/sau/services.py +++ b/sau/services.py @@ -108,6 +108,7 @@ def restart_services(): services[proc_name] = service_name processes[service_name] = [proc] + recommend_restart = False for service in set([x for x in services.values() if x]): policy = _get_service_restart_policy(service) if policy == 'ignore': @@ -116,11 +117,13 @@ def restart_services(): elif policy == 'warn': log.warning('Service "{}" has open deleted files and should be restarted'.format(service)) continue - if not policy.startswith('silent'): + elif policy == 'reboot': + log.warning('Rebooting because {} has opened files'.format(service)) + recommend_restart = True + if not ( policy.startswith('silent') or policy == 'reboot' ): log.warning('Restarting service {}'.format(service)) platform.restart_service(service) - recommend_restart = False tested_parents = set() for proc in retest_procs: parent = _get_top_parent(proc) @@ -157,13 +160,13 @@ 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'): + if policy and policy.lower() in ('restart', 'warn', 'ignore', 'silent-restart', 'reboot'): return policy.lower() elif policy: log.warning('service policy {} for {} is invalid'.format(policy, service)) default_policy = conf.get('default', 'default_service_policy', fallback='warn') - if default_policy.lower() in ('restart', 'warn', 'ignore', 'silent-restart'): + if default_policy.lower() in ('restart', 'warn', 'ignore', 'silent-restart', 'reboot'): return default_policy.lower() log.warning('default service policy {} is invalid'.format(default_policy)) return 'warn'