From 04cbedb9c0ed71fa6708906136791f98bed0c47b Mon Sep 17 00:00:00 2001 From: Fredrik Eriksson Date: Sat, 12 Oct 2019 21:37:26 +0200 Subject: [PATCH] added option to reboot for specific services --- config.cfg | 2 +- sau/services.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) 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'