added support for silent-reboot and gentoo without gentoo-sources kernel

This commit is contained in:
Fredrik Eriksson 2019-12-16 20:03:49 +01:00
parent 79dd24809d
commit 1322918dcc
Signed by: feffe
GPG Key ID: 18524638BE25530A
2 changed files with 15 additions and 9 deletions

View File

@ -1,3 +1,4 @@
import os
import platform import platform
import sau.errors import sau.errors
@ -9,9 +10,10 @@ def get_platform():
if platform.system() == 'FreeBSD': if platform.system() == 'FreeBSD':
platform_mod = sau.freebsd platform_mod = sau.freebsd
elif platform.system() == 'Linux': elif platform.system() == 'Linux':
if 'gentoo' in platform.release(): if os.path.exists('/usr/bin/emerge'):
platform_mod = sau.gentoo platform_mod = sau.gentoo
if not platform_mod: if not platform_mod:
raise sau.errors.PlatformNotSupported("System: {} Release: {} Version: {} is not supported".format( raise sau.errors.PlatformNotSupported("System: {} Release: {} Version: {} is not supported".format(
platform.system(), platform.system(),

View File

@ -12,6 +12,10 @@ import sau.platforms
proc_fd_map_re = re.compile(r'^.*(/[^\(]*) \(deleted\)$') 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): def _get_deleted_open_files(proc):
log = logging.getLogger(sau.LOGNAME) log = logging.getLogger(sau.LOGNAME)
files = set() files = set()
@ -117,11 +121,10 @@ def restart_services():
elif policy == 'warn': elif policy == 'warn':
log.warning('Service "{}" has open deleted files and should be restarted'.format(service)) log.warning('Service "{}" has open deleted files and should be restarted'.format(service))
continue continue
elif policy == 'reboot': elif 'reboot' in policy:
log.warning('Rebooting because {} has opened files'.format(service)) _warn('Rebooting because {} has opened files'.format(service))
recommend_restart = True recommend_restart = True
if not ( policy.startswith('silent') or policy == 'reboot' ): _warn('Restarting service {}'.format(service))
log.warning('Restarting service {}'.format(service))
platform.restart_service(service) platform.restart_service(service)
tested_parents = set() tested_parents = set()
@ -137,14 +140,15 @@ def restart_services():
if _get_deleted_open_files(proc): if _get_deleted_open_files(proc):
tested_parents.add(parent) tested_parents.add(parent)
service = _get_service_from_proc(parent) service = _get_service_from_proc(parent)
policy = _get_service_restart_policy(service)
if not 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 recommend_restart = True
continue continue
log.debug('{} is in service {}'.format(proc, service)) log.debug('{} is in service {}'.format(proc, service))
if parent_name in services and not services[parent_name]: 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 recommend_restart = True
continue continue
elif parent_name in services: elif parent_name in services:
@ -152,7 +156,7 @@ def restart_services():
log.debug('service {} has policy {}'.format(service, policy)) log.debug('service {} has policy {}'.format(service, policy))
if policy in ('ignore', 'warn'): if policy in ('ignore', 'warn'):
continue 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 recommend_restart = True
return recommend_restart return recommend_restart
@ -160,7 +164,7 @@ def _get_service_restart_policy(service):
log = logging.getLogger(sau.LOGNAME) log = logging.getLogger(sau.LOGNAME)
conf = sau.config conf = sau.config
policy = conf.get('services', service, fallback=None) 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() return policy.lower()
elif policy: elif policy:
log.warning('service policy {} for {} is invalid'.format(policy, service)) log.warning('service policy {} for {} is invalid'.format(policy, service))