Compare commits

..

13 Commits

4 changed files with 124 additions and 105 deletions

View File

@ -45,6 +45,11 @@ do_depclean=yes
# do eix-sync on Gentoo # do eix-sync on Gentoo
do_reposync=yes do_reposync=yes
# do live-rebuild, go-rebuild, rust-rebuild, perl-cleaner etc. on Gentoo
# set to no if using binary packages that are bumped when needed.
# Leave as yes on package builders and if not using binary packages.
do_rebuilds=yes
# to only write to stderr when something unexpected happens or manual action is required # to only write to stderr when something unexpected happens or manual action is required
# set stderr_loglevel to warning # set stderr_loglevel to warning
stderr_loglevel=debug stderr_loglevel=debug

View File

@ -119,6 +119,9 @@ def is_system_package(atom, eclasses):
log.debug(f"{name} is a sys-boot package") log.debug(f"{name} is a sys-boot package")
return True return True
if eclasses is True:
return True
# libc-packages should be considered system-packages as they generally # libc-packages should be considered system-packages as they generally
# requires the system to be restarted. Not sure if there is a better way # requires the system to be restarted. Not sure if there is a better way
# then just checking for specific packages here, but as far as I know there # then just checking for specific packages here, but as far as I know there
@ -140,7 +143,7 @@ def is_system_package(atom, eclasses):
def get_eclasses(atom): def get_eclasses(atom):
log = logging.getLogger(sau.LOGNAME) log = logging.getLogger(sau.LOGNAME)
eclasses = [] eclasses = []
name=re.sub(r'^[<=>]*(.*?)(?:-\d)?(?:::\w+)?$', r'\1', atom) name=re.sub(r'^[<=>]*(.*?)(?:-\d+)?(?:::\w+)?$', r'\1', atom)
test_re = re.compile(r'^\s*inherit\s+') test_re = re.compile(r'^\s*inherit\s+')
cmd=[ EQUERY_PATH, 'w', name ] cmd=[ EQUERY_PATH, 'w', name ]
ret, out, err = sau.helpers.exec_cmd(cmd) ret, out, err = sau.helpers.exec_cmd(cmd)
@ -168,7 +171,7 @@ def get_eclasses(atom):
return eclasses return eclasses
def get_dependencies(atom): def get_dependencies(atom):
cmd=[ EQUERY_PATH, '-q', 'd', '-F', '$cp', name ] cmd=[ EQUERY_PATH, '-q', 'd', '-F', '$cp', atom ]
ret, out, err = sau.helpers.exec_cmd(cmd) ret, out, err = sau.helpers.exec_cmd(cmd)
dependencies = [l.strip() for l in out.splitlines()] dependencies = [l.strip() for l in out.splitlines()]
return dependencies return dependencies
@ -261,113 +264,116 @@ def pkg_upgrade():
if line.startswith(' * '): if line.startswith(' * '):
log.warning(line) log.warning(line)
# from here on we shouldn't need to rebuild the upgraded packages again ## rebuild as needed
exclude_list = ' --exclude '.join(rebuild_packages.keys()).split() do_rebuild = conf.getboolean('default', 'do_rebuilds', fallback=True)
if do_rebuild:
# from here on we shouldn't need to rebuild the upgraded packages again
exclude_list = ' --exclude '.join(rebuild_packages.keys()).split()
# Rebuild go # Rebuild go
go_packages = [] go_packages = []
cmd = None cmd = None
for package,eclasses in rebuild_packages.items(): for package,eclasses in rebuild_packages.items():
if 'go-module' in eclasses or package == 'dev-lang/go': if 'go-module' in eclasses or package == 'dev-lang/go':
go_packages.append(package) go_packages.append(package)
if 'dev-lang/go' in go_packages: if 'dev-lang/go' in go_packages:
log.info("Running golang-rebuild due to update of dev-lang/go") log.info("Running golang-rebuild due to update of dev-lang/go")
cmd = [
EMERGE_PATH,
'--color', 'n',
'-q',
'--usepkg-exclude', '*/*',
'@golang-rebuild',
'--exclude' ] + exclude_list
elif go_packages:
dependencies = []
for package in go_packages:
dependencies.append(get_dependencies(package))
dependencies = set(dependencies)
upgraded = set(rebuild_packages.keys())
not_upgraded = dependencies-upgraded
if not_upgraded:
log.info(f'Rebuilding packages dependant of go modules {", ".join(go_packages)}')
cmd = [ cmd = [
EMERGE_PATH, EMERGE_PATH,
'--color', 'n', '--color', 'n',
'-q', '-q',
'--usepkg-exclude', '*/*'] + not_upgraded '--usepkg', 'n',
if cmd: '@golang-rebuild',
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=72000) '--exclude' ] + exclude_list
elif go_packages:
dependencies = []
for package in go_packages:
dependencies.extend(get_dependencies(package))
dependencies = set(dependencies)
upgraded = set(rebuild_packages.keys())
not_upgraded = dependencies-upgraded
if not_upgraded:
log.info(f'Rebuilding packages dependant of go modules {", ".join(go_packages)}')
cmd = [
EMERGE_PATH,
'--color', 'n',
'-q',
'--usepkg', 'n'] + not_upgraded
if cmd:
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=72000)
if ret != 0 or err:
log.error('Rebuild of go packages returned {}'.format(ret))
for line in out.splitlines():
log.error('stdout: {}'.format(line))
for line in err.splitlines():
log.error('stderr: {}'.format(line))
raise sau.errors.UpgradeError(f'Error during go rebuild')
else:
log.info('go rebuild complete')
for line in out.splitlines():
if line.startswith(' * '):
log.warning(line)
# rebuild rust
if any([x in rebuild_packages for x in ('dev-lang/rust', 'dev-lang/rust-bin')]):
log.info("Running rust-rebuild due to update of rust")
cmd = [
EMERGE_PATH,
'--color', 'n',
'-q',
'--usepkg', 'n',
'@rust-rebuild',
'--exclude' ] + exclude_list
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=72000)
if ret != 0 or err:
log.error('Rebuild of rust packages returned {}'.format(ret))
for line in out.splitlines():
log.error('stdout: {}'.format(line))
for line in err.splitlines():
log.error('stderr: {}'.format(line))
raise sau.errors.UpgradeError(f'Error during rust rebuild')
else:
log.info('rust rebuild complete')
for line in out.splitlines():
if line.startswith(' * '):
log.warning(line)
# run perl-cleaner
if 'dev-lang/perl' in rebuild_packages:
log.info("Running perl-cleaner due to perl upgrade")
cmd = [ PCLEAN_PATH, '--all', '--', '-q', '--usepkg', 'n']
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=72000)
if ret != 0 or err:
log.error('perl-cleaner failed with code {}'.format(ret))
for line in out.splitlines():
log.error('stdout: {}'.format(line))
for line in err.splitlines():
log.error('stderr: {}'.format(line))
raise sau.errors.UpgradeError(f'Error during perl-cleaner')
else:
log.info('perl-cleaner complete')
for line in out.splitlines():
if line.startswith(' * '):
log.warning(line)
# rebuild live packages
cmd = [ EMERGE_PATH, '--color', 'n', '-q', '--usepkg', 'n', '@live-rebuild' ]
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=3600)
if ret != 0 or err: if ret != 0 or err:
log.error('Rebuild of go packages returned {}'.format(ret)) log.error('live-rebuild returned {}'.format(ret))
for line in out.splitlines(): for line in out.splitlines():
log.error('stdout: {}'.format(line)) log.error('stdout: {}'.format(line))
for line in err.splitlines(): for line in err.splitlines():
log.error('stderr: {}'.format(line)) log.error('stderr: {}'.format(line))
raise sau.errors.UpgradeError(f'Error during go rebuild') raise sau.errors.UpgradeError(f'Error during live-rebuild')
else: else:
log.info('go rebuild complete') log.info('live-rebuild complete')
for line in out.splitlines(): for line in out.splitlines():
if line.startswith(' * '): if line.startswith(' * '):
log.warning(line) log.warning(line)
# rebuild rust
if 'dev-lang/rust' in rebuild_packages:
log.info("Running rust-rebuild due to update of dev-lang/rust")
cmd = [
EMERGE_PATH,
'--color', 'n',
'-q',
'--usepkg-exclude', '*/*',
'@rust-rebuild',
'--exclude' ] + exclude_list
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=72000)
if ret != 0 or err:
log.error('Rebuild of rust packages returned {}'.format(ret))
for line in out.splitlines():
log.error('stdout: {}'.format(line))
for line in err.splitlines():
log.error('stderr: {}'.format(line))
raise sau.errors.UpgradeError(f'Error during rust rebuild')
else:
log.info('rust rebuild complete')
for line in out.splitlines():
if line.startswith(' * '):
log.warning(line)
# run perl-cleaner ## Depclean
if 'dev-lang/perl' in rebuild_packages:
log.info("Running perl-cleaner due to perl upgrade")
cmd = [ PCLEAN_PATH, '--all', '--', '-q', '--usepkg-exclude', '*/*']
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=72000)
if ret != 0 or err:
log.error('perl-cleaner failed with code {}'.format(ret))
for line in out.splitlines():
log.error('stdout: {}'.format(line))
for line in err.splitlines():
log.error('stderr: {}'.format(line))
raise sau.errors.UpgradeError(f'Error during perl-cleaner')
else:
log.info('perl-cleaner complete')
for line in out.splitlines():
if line.startswith(' * '):
log.warning(line)
# rebuild live packages
cmd = [ EMERGE_PATH, '--color', 'n', '-q', '--usepkg-exclude', '*/*', '@live-rebuild' ]
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=3600)
if ret != 0 or err:
log.error('live-rebuild returned {}'.format(ret))
for line in out.splitlines():
log.error('stdout: {}'.format(line))
for line in err.splitlines():
log.error('stderr: {}'.format(line))
raise sau.errors.UpgradeError(f'Error during live-rebuild')
else:
log.info('live-rebuild complete')
for line in out.splitlines():
if line.startswith(' * '):
log.warning(line)
# Depclean
if conf.getboolean('default', 'do_depclean', fallback=False): if conf.getboolean('default', 'do_depclean', fallback=False):
cmd = [ EMERGE_PATH, '--color', 'n', '-q', '--depclean' ] cmd = [ EMERGE_PATH, '--color', 'n', '-q', '--depclean' ]
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=3600) ret, out, err = sau.helpers.exec_cmd(cmd, timeout=3600)
@ -385,8 +391,8 @@ def pkg_upgrade():
log.warning(line) log.warning(line)
# Preserved rebuild ## Preserved rebuild
cmd = [ EMERGE_PATH, '--color', 'n', '-q', '@preserved-rebuild' ] cmd = [ EMERGE_PATH, '--color', 'n', '--usepkg', 'n', '-q', '@preserved-rebuild' ]
ret, out, err = sau.helpers.exec_cmd(cmd, timeout=72000) ret, out, err = sau.helpers.exec_cmd(cmd, timeout=72000)
if ret != 0 or err: if ret != 0 or err:

View File

@ -10,7 +10,10 @@ import sau.errors
import sau.helpers import sau.helpers
import sau.platforms import sau.platforms
proc_fd_map_re = re.compile(r'^.*(/[^\(]*) \(deleted\)$') 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): def _warn(policy, msg):
log = logging.getLogger(sau.LOGNAME) log = logging.getLogger(sau.LOGNAME)
@ -28,7 +31,8 @@ def get_deleted_open_files(proc):
for line in f: for line in f:
match = re.match(proc_fd_map_re, line) match = re.match(proc_fd_map_re, line)
if match: if match:
files.add(match.group(1)) fname = match.group(1)
files.add(fname)
return files return files
# on FreeBSD psutils open_files() helpfully returns a null path if a file # on FreeBSD psutils open_files() helpfully returns a null path if a file
@ -116,7 +120,6 @@ def restart_services():
retest_procs.add(proc) retest_procs.add(proc)
recommend_restart = False recommend_restart = False
processes = {}
services = {} services = {}
for proc in service_procs: for proc in service_procs:
if not proc: if not proc:
@ -141,15 +144,17 @@ def restart_services():
sau.helpers.exec_cmd([ '/usr/bin/systemctl', 'daemon-reexec' ]) sau.helpers.exec_cmd([ '/usr/bin/systemctl', 'daemon-reexec' ])
continue continue
elif service_name == '@ignore': elif service_name == '@ignore':
log.info(f"Process {proc} ignored by configuration")
retest_procs.discard(proc)
continue continue
services[proc_name] = service_name services[proc_name] = service_name
processes[service_name] = [proc]
for service in set([x for x in services.values() if x]): for service in set([x for x in services.values() if x]):
policy = _get_service_restart_policy(service) policy = _get_service_restart_policy(service)
if policy == 'ignore': if policy == 'ignore':
log.info('Service "{}" ignored by configuration'.format(service)) log.info('Service "{}" ignored by configuration'.format(service))
[retest_procs.discard(x) for x,y in services.items() if y == service]
continue continue
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))
@ -180,7 +185,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', 'silent-reboot'): if policy and policy.lower() in valid_service_policies:
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))
@ -228,6 +233,9 @@ def _get_service_from_proc(proc):
log.warning(f'Not restarting user service {unit}; please log out and log in again') log.warning(f'Not restarting user service {unit}; please log out and log in again')
return None return None
else: 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 ]) _ret, enabled, _err = sau.helpers.exec_cmd([ '/usr/bin/systemctl', 'is-enabled', unit ])
enabled = enabled.strip() enabled = enabled.strip()
if enabled not in ('enabled', 'static'): if enabled not in ('enabled', 'static'):

View File

@ -1,11 +1,11 @@
#!/usr/bin/env python3.7 #!/usr/bin/env python3
from os import environ from os import environ
from setuptools import setup, find_packages from setuptools import setup, find_packages
setup( setup(
name='sau', name='sau',
version='1.3.4', version='1.4.5',
description='Tool for auto-updating OS and packages', description='Tool for auto-updating OS and packages',
author='Feffe', author='Feffe',
author_email='feffe@fulh.ax', author_email='feffe@fulh.ax',