allow to explicit restart service even if not enabled

This commit is contained in:
Fredrik Eriksson 2024-08-17 08:54:43 +02:00
parent 29c1256ee1
commit cc206f6198
Signed by: feffe
GPG Key ID: E6B5580B853D322B
2 changed files with 8 additions and 2 deletions

View File

@ -12,6 +12,9 @@ import sau.platforms
proc_fd_map_re = re.compile(r'^.*(/(?:usr|lib|opt|etc|s?bin)[^\(]*) \(deleted\)$')
valid_service_policies=('restart', 'warn', 'ignore', 'silent-restart',
'reboot', 'silent-reboot')
def _warn(policy, msg):
log = logging.getLogger(sau.LOGNAME)
if not policy.startswith('silent'):
@ -182,7 +185,7 @@ 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', 'reboot', 'silent-reboot'):
if policy and policy.lower() in valid_service_policies:
return policy.lower()
elif policy:
log.warning('service policy {} for {} is invalid'.format(policy, service))
@ -230,6 +233,9 @@ def _get_service_from_proc(proc):
log.warning(f'Not restarting user service {unit}; please log out and log in again')
return None
else:
policy = conf.get('services', name, fallback=None)
if policy and policy.lower() in valid_service_policies:
return name
_ret, enabled, _err = sau.helpers.exec_cmd([ '/usr/bin/systemctl', 'is-enabled', unit ])
enabled = enabled.strip()
if enabled not in ('enabled', 'static'):

View File

@ -5,7 +5,7 @@ from setuptools import setup, find_packages
setup(
name='sau',
version='1.4.1',
version='1.4.2',
description='Tool for auto-updating OS and packages',
author='Feffe',
author_email='feffe@fulh.ax',