diff --git a/systemdspawner/systemd.py b/systemdspawner/systemd.py index 65b2771..39a2f2c 100644 --- a/systemdspawner/systemd.py +++ b/systemdspawner/systemd.py @@ -230,6 +230,14 @@ 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) @@ -237,5 +245,10 @@ def get_systemd_version(): # 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 diff --git a/systemdspawner/systemdspawner.py b/systemdspawner/systemdspawner.py index 9f2712e..06b3c72 100644 --- a/systemdspawner/systemdspawner.py +++ b/systemdspawner/systemdspawner.py @@ -2,6 +2,7 @@ import os import pwd import sys +import warnings from jupyterhub.spawner import Spawner from jupyterhub.utils import random_port @@ -157,16 +158,16 @@ def __init__(self, *args, **kwargs): systemd_version = systemd.get_systemd_version() if systemd_version is None: - self.log.warning( - "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" ) sys.exit(1) elif systemd_version < SYSTEMD_LOWEST_RECOMMENDED_VERSION: - self.log.warning( + warnings.warn( f"systemd version {SYSTEMD_LOWEST_RECOMMENDED_VERSION} or higher is recommended, version {systemd_version} is used" )