added option to reboot for specific services

This commit is contained in:
Fredrik Eriksson 2019-10-12 21:37:26 +02:00
parent 6ba04be1d3
commit 04cbedb9c0
No known key found for this signature in database
GPG Key ID: 8825C73A0FD1502A
2 changed files with 8 additions and 5 deletions

View File

@ -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]

View File

@ -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'