12 Commits

Author SHA1 Message Date
7cce11022c prepare for 1.3.4 2024-07-27 16:45:09 +02:00
cef0f8d8bc fix configurable process->service mapping on systemd 2024-07-27 14:00:11 +02:00
00496493cd prepare v1.3.3 2024-07-26 12:45:13 +02:00
434858174c fix live_system config 2024-07-26 12:44:35 +02:00
a4a28a1fb3 correct log message for system upgrades 2024-07-26 12:30:47 +02:00
ae560e96c0 add more system package debugging 2024-07-26 12:19:28 +02:00
9970fe3365 add debug of eclasses 2024-07-26 12:15:18 +02:00
2491df81f6 fix rust/go rebuilds on gentoo 2024-07-26 11:25:18 +02:00
9593a7d09f prepare for v1.3.1 2024-07-26 10:48:07 +02:00
093470d27d Ignore user service on systemd
Instead emit warning about the need to log out and log in again
2024-07-26 10:46:59 +02:00
c2890da0f3 fix service log message 2024-07-26 10:40:29 +02:00
2886e367b3 add live_system config option
This is to be used in environments where reboot is strictly unneeded;
such as when building packages in a chroot
2024-07-25 19:25:12 +02:00
5 changed files with 73 additions and 48 deletions

View File

@ -115,6 +115,9 @@ def main():
log.error(f'Upgrade failed: {e}')
return 1
if not conf.getboolean('default', 'live_system', fallback=True):
return 0
if conf.getboolean('default', 'do_service_restart', fallback=True):
reboot_recommended = sau.services.restart_services()

View File

@ -12,6 +12,10 @@
# 1.0.1 -> 1.0.1.1 (3)
version_sensitivity=1
# Set to no if you're using sau in an environment where running processes
# shouldn't be touched and reboots shouldn't be done, for example in chroots
live_system=yes
# sau can reboot on system upgrades (FreeBSD) or if the service restarts does
# not close all deleted files (any platform)
do_reboot=no

View File

@ -4,6 +4,7 @@ import re
import sau
import sau.helpers
import sau.services
EIX_SYNC_PATH='/usr/bin/eix-sync'
RC_SERVICE_PATH='/sbin/rc-service'
@ -22,8 +23,7 @@ slot_re = re.compile(r'^(\(~\))?([^\(]+)(\([^\)]+\))$')
def identify_service_from_bin(exe):
log = logging.getLogger(sau.LOGNAME)
with open('/proc/1/comm', 'r') as f:
if f.readline().strip() == 'systemd':
if sau.services.on_systemd():
init_script_re = re.compile(r'[^/]*(.*)\.service$')
else:
init_script_re = re.compile(r'/etc/init\.d/(.*)')
@ -61,8 +61,7 @@ def identify_service_from_bin(exe):
def restart_service(service):
log = logging.getLogger(sau.LOGNAME)
with open('/proc/1/comm', 'r') as f:
if f.readline().strip() == 'systemd':
if sau.services.on_systemd():
cmd = [ SYSTEMCTL, 'restart', service ]
else:
cmd = [ RC_SERVICE_PATH, service, 'restart' ]
@ -117,6 +116,7 @@ def is_system_package(atom, eclasses):
# sys-boot/ category should probably always be considered
# system-packages
if name.split('/')[0] == 'sys-boot':
log.debug(f"{name} is a sys-boot package")
return True
# libc-packages should be considered system-packages as they generally
@ -124,6 +124,7 @@ def is_system_package(atom, eclasses):
# then just checking for specific packages here, but as far as I know there
# are not many of them anyway...
if re.search(r'^sys-libs/(glibc|musl)', name):
log.debug(f"{name} is a libc package")
return True
if any([
@ -132,6 +133,7 @@ def is_system_package(atom, eclasses):
'linux-mod',
'kernel-install' ]
]):
log.debug(f"{name} is of system eclass (eclasses: {eclasses})")
return True
return False
@ -233,7 +235,7 @@ def pkg_upgrade():
if do_system_upgrade:
do_grub = True
else:
raise sau.errors.UpgradeError(f"System package {name} has an update, but system upgrade is disabled")
raise sau.errors.UpgradeError(f"System package {package} has an update, but system upgrade is disabled")
if not do_rebuild:
raise sau.errors.UpgradeError('Some packages require manual attention, did not upgrade')
@ -260,7 +262,7 @@ def pkg_upgrade():
log.warning(line)
# from here on we shouldn't need to rebuild the upgraded packages again
exclude_list = '--exclude '.join(rebuild_packages.keys()).split()
exclude_list = ' --exclude '.join(rebuild_packages.keys()).split()
# Rebuild go
go_packages = []

View File

@ -75,6 +75,16 @@ def _get_processes():
return check_procs
# Just return True if system is running on systemd
def on_systemd():
try:
init_proc = psutil.Process(pid=1)
if init_proc.name() == 'systemd':
return True
except psutil.NoSuchProcess:
pass
return False
def restart_services():
log = logging.getLogger(sau.LOGNAME)
platform = sau.platforms.get_platform()
@ -84,14 +94,6 @@ def restart_services():
# wait before the second test
time.sleep(5)
on_systemd = False
try:
init_proc = psutil.Process(pid=1)
if init_proc.name() == 'systemd':
on_systemd = True
except psutil.NoSuchProcess:
pass
# perform a second check to remove potential false positives
service_procs = set()
retest_procs = set()
@ -105,7 +107,7 @@ def restart_services():
except (psutil.NoSuchProcess, psutil.ZombieProcess, psutil.AccessDenied):
# either of the above exceptions means the process has quit
continue
if on_systemd:
if on_systemd():
service_procs.add(proc)
else:
parent = _get_top_parent(proc)
@ -128,33 +130,18 @@ def restart_services():
log.debug('{} died before it could be restarted'.format(proc))
continue
if on_systemd:
if proc.pid == 1:
log.info("Upgrade of systemd detected; doing daemon-reexec")
ret, _out, _err = sau.helpers.exec_cmd([ '/usr/bin/systemctl', 'daemon-reexec' ])
continue
ret, unit, err = sau.helpers.exec_cmd([ '/usr/bin/systemctl', 'whoami', f'{proc.pid}' ])
unit = unit.strip()
name, unit_type = unit.split('.')
if ret != 0:
log.debug(f'Non-success ({ret}) when checking unit for process: {err}')
continue
elif unit_type != 'service':
log.warning(f'not restarting non-service unit "{unit}"; owner of {proc}')
else:
_ret, enabled, _err = sau.helpers.exec_cmd([ '/usr/bin/systemctl', 'is-enabled', unit ])
enabled = enabled.strip()
if enabled not in ('enabled', 'static'):
log.warning(f'Unit {name}.service has enable status: {enabled} - will only restart "enabled" services')
else:
service_name = name
else:
service_name = _get_service_from_proc(proc)
if not service_name:
log.warning('no service for process {}'.format(proc))
recommend_restart = True
continue
if service_name == 'systemd':
log.info("Upgrade of systemd detected; doing daemon-reexec")
sau.helpers.exec_cmd([ '/usr/bin/systemctl', 'daemon-reexec' ])
continue
elif service_name == '@ignore':
continue
services[proc_name] = service_name
processes[service_name] = [proc]
@ -185,7 +172,7 @@ def restart_services():
if get_deleted_open_files(proc):
service = services[proc_name]
policy = _get_service_restart_policy(service)
_warn(policy, '{} still has deleted files open'.format(proc, parent))
_warn(policy, f'{proc} still has deleted files open')
recommend_restart = True
return recommend_restart
@ -207,6 +194,7 @@ def _get_service_restart_policy(service):
def _get_service_from_proc(proc):
conf = sau.config
platform = sau.platforms.get_platform()
if not on_systemd():
proc = _get_top_parent(proc)
log = logging.getLogger(sau.LOGNAME)
try:
@ -214,14 +202,42 @@ def _get_service_from_proc(proc):
service_exe = proc.exe()
except (psutil.NoSuchProcess, psutil.ZombieProcess, psutil.AccessDenied):
log.debug('{} died'.format(proc))
return None
return '@ignore'
service_name = conf.get('processes', proc_name, fallback=None)
log.debug(f'configuration of process "{proc_name}" in config: "{service_name}"')
if service_name == '':
log.debug('Ignoring process {}'.format(proc))
return None
return '@ignore'
if not service_name:
# Systemd has it's own way...
if on_systemd():
if proc.pid == 1:
return 'systemd'
ret, unit, err = sau.helpers.exec_cmd([ '/usr/bin/systemctl', 'whoami', f'{proc.pid}' ])
unit = unit.strip()
name, unit_type = unit.split('.')
if ret != 0:
log.debug(f'Non-success ({ret}) when checking unit for process: {err}')
return None
elif unit_type != 'service':
log.warning(f'not restarting non-service unit "{unit}"; owner of {proc}')
return None
elif name.startswith('user@'):
log.warning(f'Not restarting user service {unit}; please log out and log in again')
return None
else:
_ret, enabled, _err = sau.helpers.exec_cmd([ '/usr/bin/systemctl', 'is-enabled', unit ])
enabled = enabled.strip()
if enabled not in ('enabled', 'static'):
log.warning(f'Unit {name}.service has enable status: {enabled} - will only restart "enabled" services')
return None
else:
return name
log.error(f'This should be an unreachable path when checking process {proc}')
return None
# if the exe file has been deleted since started, service_exe will be empty
# and we'll have to guess
if not service_exe:

View File

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