diff --git a/config.cfg b/config.cfg index d9925ee..120b798 100644 --- a/config.cfg +++ b/config.cfg @@ -59,6 +59,9 @@ gitlab-workhorse=gitlab qemu-system-x86_64= # The services section contains restart policy for specific services. -# valid policies are 'ignore', 'warn' and 'restart'. +# valid policies are 'ignore', 'warn', 'restart' and 'silent-restart'. +# 'silent-restart' is like 'restart', but will not log a warning when +# the service is restarted. [services] libvirtd=ignore +php-fpm=silent-restart diff --git a/sau/services.py b/sau/services.py index 6c60f81..c989f3b 100644 --- a/sau/services.py +++ b/sau/services.py @@ -99,8 +99,7 @@ def restart_services(): service_procs.add(parents[-2]) retest_procs.add(proc) - services = set() - processes = set() + processes = {} services = {} for proc in service_procs: try: @@ -111,6 +110,7 @@ def restart_services(): continue if proc_name in services: + processes[services[proc_name]].append(proc) # we have already checked a process with this name continue @@ -137,6 +137,7 @@ def restart_services(): continue services[proc_name] = service_name + processes[service_name] = [proc] for service in [x for x in services.values() if x]: policy = _get_service_restart_policy(service) @@ -147,7 +148,8 @@ def restart_services(): log.warning('Service "{}" has open deleted files and should be restarted'.format(service)) continue - log.info('Restarting service {}'.format(service)) + if not policy.startswith('silent'): + log.warning('Restarting service {}'.format(service)) platform.restart_service(service) recommend_restart = False @@ -174,13 +176,13 @@ def restart_services(): def _get_service_restart_policy(service): conf = sau.config policy = conf.get('services', service, fallback=None) - if policy and policy.lower() in ('restart', 'warn', 'ignore'): + if policy and policy.lower() in ('restart', 'warn', 'ignore', 'silent-restart'): return policy.lower() elif policy: log.warning('service policy {} for {} is invalid'.format(policy, service)) default_policy = conf.get('services', 'default_service_policy', fallback='warn') - if default_policy.lower() in ('restart', 'warn', 'ignore'): + if default_policy.lower() in ('restart', 'warn', 'ignore', 'silent-restart'): return default_policy.lower() log.warning('default service policy {} is invalid'.format(default_policy)) return 'warn'