* 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 settings in the default section (obviously)
[default] [default]
# version_diff represents (hopefully) the compatibility change for the package. # version_sensitivity represents how many point fields (counting from left) that must
# It works by starting with the number of dots in the version scheme + 1, and # match in the versioning scheme for automatic upgrades to be allowed. Typically
# then removes 1 for every field that is the same in the current and new # you want to set this to 1 to not auto-update major version that may brake things
# version. Some examples: # Some examples:
# 1.0.0 -> 1.0.0 (level 0, a reinstall of the same version) # 1.0.0 -> 1.0.0 (3)
# 1.0.0 -> 1.0.1 (level 1) # 1.0.0 -> 1.0.1 (2)
# 1.0.0 -> 1.1.0 (level 2) # 1.0.0 -> 1.1.0 (1)
# 1.0.0 -> 2.0.0 (level 3) # 1.0.0 -> 2.0.0 (0)
# 1.0.0.0 -> 2.0.0.0 (level 4) # 1.0.0.0 -> 2.0.0.0 (0)
# 1.0.1 -> 1.0.1.1 (level 2, because that's how it turned out...) # 1.0.1 -> 1.0.1.1 (3)
min_version_diff=2 version_sensitivity=1
# sau can reboot on system upgrades (FreeBSD) or if the service restarts does # sau can reboot on system upgrades (FreeBSD) or if the service restarts does
# not close all deleted files (any platform) # not close all deleted files (any platform)
@ -36,18 +36,20 @@ stderr_loglevel=debug
syslog_loglevel=info syslog_loglevel=info
# The packages section contains <package>=<version_diff> pairs to override the # The packages section contains <package>=<version_sensitivity> pairs to override the
# default min_version_diff. Note that package naming may differ depending on # default version_sensitivity. Note that package naming may differ depending on
# platform # platform
[packages] [packages]
# Gentoo kernel stuff should be updated manually # Gentoo uses the category/package naming scheme
sys-kernel/gentoo-sources=0 dev-db/postgresql=2
sys-kernel/spl=0
sys-fs/zfs-kmod=0
dev-db/postgresql=1
# FreeBSD uses the short package name # Gentoo kernel stuff should be updated manually
gitlab=1 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> # The processes section contains <process-name>=<service-name>
@ -58,6 +60,9 @@ gitlab=1
gitlab-workhorse=gitlab gitlab-workhorse=gitlab
qemu-system-x86_64= qemu-system-x86_64=
# sometimes multiple services will have to be restarted
#ruby24=puppetserver puppetdb
# The services section contains restart policy for specific services. # The services section contains restart policy for specific services.
# valid policies are 'ignore', 'warn', 'restart' and 'silent-restart'. # valid policies are 'ignore', 'warn', 'restart' and 'silent-restart'.
# 'silent-restart' is like 'restart', but will not log a warning when # '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)) log.warning('stderr: {}'.format(line))
return False 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: for pkg in upgrades:
pkg['upgrade_level'] = sau.helpers.version_diff(pkg['version_new'], pkg['version_old']) pkg['upgrade_level'] = sau.helpers.version_diff(pkg['version_new'], pkg['version_old'])
log.info('pkg upgrade available {}'.format(pkg)) log.info('pkg upgrade available {}'.format(pkg))
diff = conf.getint('packages', pkg['pkg'], fallback=default_version_diff) sens = conf.getint('packages', pkg['pkg'], fallback=default_version_sens)
if diff >= pkg['upgrade_level']: if sens <= pkg['upgrade_level']:
log.debug('configured level {} >= pkg level {}'.format(diff, pkg['upgrade_level'])) log.debug('configured level {} <= pkg level {}'.format(sens, pkg['upgrade_level']))
pkg['upgrade'] = True pkg['upgrade'] = True
else: 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 pkg['upgrade'] = False
for pkg in [x for x in upgrades if not x['upgrade']]: 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.*)$') 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' ] cmd = [ EMERGE_PATH, '--color', 'n', '-uDNpq', '@world' ]
ret, out, err = sau.helpers.exec_cmd(cmd) ret, out, err = sau.helpers.exec_cmd(cmd)
@ -144,12 +144,12 @@ def pkg_upgrade():
name = nmatch.group(1) name = nmatch.group(1)
version = nmatch.group(2) version = nmatch.group(2)
min_diff = conf.getint('packages', name, fallback=default_version_diff) sens = conf.getint('packages', name, fallback=default_version_sens)
diff = sau.helpers.version_diff(version, old) common = sau.helpers.version_diff(version, old)
if min_diff >= diff: if sens <= common:
log.info('{}-{} -> {} configured level {} >= pkg level {}'.format(name, old, version, min_diff, diff)) log.info('{}-{} -> {} configured level {} <= pkg level {}'.format(name, old, version, sens, common))
else: 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 do_rebuild = False
if not do_rebuild: if not do_rebuild:

View File

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

View File

@ -136,18 +136,19 @@ def restart_services():
services[proc_name] = service_name services[proc_name] = service_name
processes[service_name] = [proc] 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]:
policy = _get_service_restart_policy(service) for service in service_all.split():
if policy == 'ignore': policy = _get_service_restart_policy(service)
log.info('Service "{}" ignored by configuration'.format(service)) if policy == 'ignore':
continue log.info('Service "{}" ignored by configuration'.format(service))
elif policy == 'warn': continue
log.warning('Service "{}" has open deleted files and should be restarted'.format(service)) elif policy == 'warn':
continue log.warning('Service "{}" has open deleted files and should be restarted'.format(service))
continue
if not policy.startswith('silent'): if not policy.startswith('silent'):
log.warning('Restarting service {}'.format(service)) log.warning('Restarting service {}'.format(service))
platform.restart_service(service) platform.restart_service(service)
recommend_restart = False recommend_restart = False
for proc in retest_procs: for proc in retest_procs: