Skip to content

Commit

Permalink
warn about specific errors retrieving systemd version
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Jun 8, 2023
1 parent 67087e8 commit 2149f4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 14 additions & 1 deletion systemdspawner/systemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,25 @@ def get_systemd_version():
"""
try:
version_response = subprocess.check_output(["systemctl", "--version"])
except Exception as e:
warnings.warn(
f"Failed to run `systemctl --version` to get systemd version: {e}",
RuntimeWarning,
stacklevel=2,
)

try:
# Example response from Ubuntu 22.04:
#
# systemd 249 (249.11-0ubuntu3.9)
# +PAM +AUDIT +SELINUX +APPARMOR +IMA +SMACK +SECCOMP +GCRYPT +GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBFDISK +PCRE2 -PWQUALITY -P11KIT -QRENCODE +BZIP2 +LZ4 +XZ +ZLIB +ZSTD -XKBCOMMON +UTMP +SYSVINIT default-hierarchy=unified
#
version = int(float(version_response.split()[1]))
return version
except:
except Exception as e:
warnings.warn(
f"Failed to parse systemd version from `systemctl --version`: {e}. output={version_response}",
RuntimeWarning,
stacklevel=2,
)
return None
4 changes: 3 additions & 1 deletion systemdspawner/systemdspawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ def __init__(self, *args, **kwargs):

systemd_version = systemd.get_systemd_version()
if systemd_version is None:
warnings.warn("Failed to parse systemd version from 'systemctl --version'")
# not found, nothing to check
# already warned about this in get_systemd_version
pass
elif systemd_version < SYSTEMD_REQUIRED_VERSION:
self.log.critical(
f"systemd version {SYSTEMD_REQUIRED_VERSION} or higher is required, version {systemd_version} is used"
Expand Down

0 comments on commit 2149f4a

Please sign in to comment.