* allow mapping processes to multiple init-scripts

* reverse-ish the version logic
This commit is contained in:
Fredrik Eriksson 2019-04-18 10:31:00 +02:00
parent f121466eaa
commit 6f69be3f6a
No known key found for this signature in database
GPG Key ID: 8825C73A0FD1502A
5 changed files with 54 additions and 52 deletions

View File

@ -1,16 +1,16 @@
# Default settings in the default section (obviously)
[default]
# version_diff represents (hopefully) the compatibility change for the package.
# It works by starting with the number of dots in the version scheme + 1, and
# then removes 1 for every field that is the same in the current and new
# version. Some examples:
# 1.0.0 -> 1.0.0 (level 0, a reinstall of the same version)
# 1.0.0 -> 1.0.1 (level 1)
# 1.0.0 -> 1.1.0 (level 2)
# 1.0.0 -> 2.0.0 (level 3)
# 1.0.0.0 -> 2.0.0.0 (level 4)
# 1.0.1 -> 1.0.1.1 (level 2, because that's how it turned out...)
min_version_diff=2
# version_sensitivity represents how many point fields (counting from left) that must
# match in the versioning scheme for automatic upgrades to be allowed. Typically
# you want to set this to 1 to not auto-update major version that may brake things
# Some examples:
# 1.0.0 -> 1.0.0 (3)
# 1.0.0 -> 1.0.1 (2)
# 1.0.0 -> 1.1.0 (1)
# 1.0.0 -> 2.0.0 (0)
# 1.0.0.0 -> 2.0.0.0 (0)
# 1.0.1 -> 1.0.1.1 (3)
version_sensitivity=1
# sau can reboot on system upgrades (FreeBSD) or if the service restarts does
# not close all deleted files (any platform)
@ -36,18 +36,20 @@ stderr_loglevel=debug
syslog_loglevel=info
# The packages section contains <package>=<version_diff> pairs to override the
# default min_version_diff. Note that package naming may differ depending on
# The packages section contains <package>=<version_sensitivity> pairs to override the
# default version_sensitivity. Note that package naming may differ depending on
# platform
[packages]
# Gentoo kernel stuff should be updated manually
sys-kernel/gentoo-sources=0
sys-kernel/spl=0
sys-fs/zfs-kmod=0
dev-db/postgresql=1
# Gentoo uses the category/package naming scheme
dev-db/postgresql=2
# FreeBSD uses the short package name
gitlab=1
# Gentoo kernel stuff should be updated manually
sys-kernel/gentoo-sources=-1
sys-kernel/spl=-1
sys-fs/zfs-kmod=-1
# FreeBSD uses the short package name (without category)
gitlab=2
# The processes section contains <process-name>=<service-name>
@ -58,6 +60,9 @@ gitlab=1
gitlab-workhorse=gitlab
qemu-system-x86_64=
# sometimes multiple services will have to be restarted
#ruby24=puppetserver puppetdb
# The services section contains restart policy for specific services.
# valid policies are 'ignore', 'warn', 'restart' and 'silent-restart'.
# 'silent-restart' is like 'restart', but will not log a warning when

View File

@ -107,16 +107,16 @@ def pkg_upgrade():
log.warning('stderr: {}'.format(line))
return False
default_version_diff = conf.getint('default', 'min_version_diff', fallback=2)
default_version_sens = conf.getint('default', 'version_sensitivity', fallback=1)
for pkg in upgrades:
pkg['upgrade_level'] = sau.helpers.version_diff(pkg['version_new'], pkg['version_old'])
log.info('pkg upgrade available {}'.format(pkg))
diff = conf.getint('packages', pkg['pkg'], fallback=default_version_diff)
if diff >= pkg['upgrade_level']:
log.debug('configured level {} >= pkg level {}'.format(diff, pkg['upgrade_level']))
sens = conf.getint('packages', pkg['pkg'], fallback=default_version_sens)
if sens <= pkg['upgrade_level']:
log.debug('configured level {} <= pkg level {}'.format(sens, pkg['upgrade_level']))
pkg['upgrade'] = True
else:
log.debug('configured level {} < pkg level {}'.format(diff, pkg['upgrade_level']))
log.debug('configured level {} > pkg level {}'.format(sens, pkg['upgrade_level']))
pkg['upgrade'] = False
for pkg in [x for x in upgrades if not x['upgrade']]:

View File

@ -113,7 +113,7 @@ def pkg_upgrade():
ignore_re = re.compile(r'^(|.*caus.* rebuilds.*|.*scheduled for merge.*|.*waiting for lock on.*)$')
default_version_diff = conf.getint('default', 'min_version_diff', fallback=2)
default_version_sens = conf.getint('default', 'version_sensitivity', fallback=1)
cmd = [ EMERGE_PATH, '--color', 'n', '-uDNpq', '@world' ]
ret, out, err = sau.helpers.exec_cmd(cmd)
@ -144,12 +144,12 @@ def pkg_upgrade():
name = nmatch.group(1)
version = nmatch.group(2)
min_diff = conf.getint('packages', name, fallback=default_version_diff)
diff = sau.helpers.version_diff(version, old)
if min_diff >= diff:
log.info('{}-{} -> {} configured level {} >= pkg level {}'.format(name, old, version, min_diff, diff))
sens = conf.getint('packages', name, fallback=default_version_sens)
common = sau.helpers.version_diff(version, old)
if sens <= common:
log.info('{}-{} -> {} configured level {} <= pkg level {}'.format(name, old, version, sens, common))
else:
log.warning('{}-{} -> {} configured level {} < pkg level {}'.format(name, old, version, min_diff, diff))
log.warning('{}-{} -> {} configured level {} > pkg level {}'.format(name, old, version, sens, common))
do_rebuild = False
if not do_rebuild:

View File

@ -27,18 +27,14 @@ def exec_cmd(cmd, timeout=600, env = None):
def version_diff(new, old):
""" This will return 100 if the versions are not properly compareable,
otherwise it will return the number of points that differ. Typically 3 is a
major upgrade, 2 minor, 1 point release and patch-levels. It can also
return 0 if both versions are the same."""
new_list = list(new.rsplit('.'))
old_list = list(old.rsplit('.'))
""" This will return the number of common fields in the version scheme,
counted from the left. """
new_list = list(new.split('.'))
old_list = list(old.split('.'))
common = min(len(new_list), len(old_list))
longest = max(len(new_list), len(old_list))
diff = longest-common
for i in range(0, common):
if new_list[i] == old_list[i]:
continue
return len(new_list) - i + diff
return 0
return i
return common

View File

@ -136,7 +136,8 @@ def restart_services():
services[proc_name] = service_name
processes[service_name] = [proc]
for service in [x for x in services.values() if x]:
for service_all in [x for x in services.values() if x]:
for service in service_all.split():
policy = _get_service_restart_policy(service)
if policy == 'ignore':
log.info('Service "{}" ignored by configuration'.format(service))