system_check.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import subprocess
  2. import re
  3. import logging
  4. from gpustack.utils import platform
  5. from gpustack.utils.command import is_command_available
  6. logger = logging.getLogger(__name__)
  7. def check_glibc_version(min_version='2.29'):
  8. """
  9. Check if the glibc version is greater than or equal to the specified minimum version.
  10. Raises an exception if the version is lower than the minimum required version.
  11. """
  12. if platform.system() != 'linux':
  13. return
  14. if not is_command_available('ldd'):
  15. logger.debug("ldd command not found. Skipping glibc version check.")
  16. return
  17. try:
  18. output = subprocess.check_output(['ldd', '--version'], text=True)
  19. first_line = output.splitlines()[0]
  20. match = re.search(r'(\d+\.\d+)', first_line)
  21. if not match:
  22. logger.debug(f"Failed to parse glibc version. Output: {first_line}")
  23. return
  24. version = match.group(1)
  25. def parse_ver(v):
  26. return [int(x) for x in v.split('.')]
  27. v1 = parse_ver(version)
  28. v2 = parse_ver(min_version)
  29. length = max(len(v1), len(v2))
  30. v1 += [0] * (length - len(v1))
  31. v2 += [0] * (length - len(v2))
  32. if v1 >= v2:
  33. return
  34. else:
  35. raise RuntimeError(
  36. f"glibc version {version} is lower than required {min_version}. Consider using Docker as an alternative."
  37. )
  38. except subprocess.CalledProcessError as e:
  39. logger.debug(f"Error checking glibc version: {e}")
  40. return