1
0

allow-systemd-parameterized-services.patch 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. From 9617d339273ceecd3b47cbcd8c331080faac48f8 Mon Sep 17 00:00:00 2001
  2. From: Massimiliano Torromeo <massimilianotorromeo@artera.it>
  3. Date: Mon, 14 Apr 2014 18:01:18 +0200
  4. Subject: [PATCH] Allow systemd parametrized services to be enabled by the
  5. service state.
  6. This makes the systemd.get_all function return the combined output of
  7. list-units and list-unit-files and the systemd.available function will
  8. also check for the base unit name stripped of the user parameter
  9. (e.g. dhcpcd@eth0 will be considered available if dhcpcd@.service exists)
  10. ---
  11. salt/modules/systemd.py | 18 +++++++++++++-----
  12. 1 file changed, 13 insertions(+), 5 deletions(-)
  13. diff --git a/salt/modules/systemd.py b/salt/modules/systemd.py
  14. index e2cfb1d..72079d7 100644
  15. --- a/salt/modules/systemd.py
  16. +++ b/salt/modules/systemd.py
  17. @@ -82,7 +82,7 @@ def _get_all_units():
  18. r')\s+loaded\s+(?P<active>[^\s]+)')
  19. out = __salt__['cmd.run_stdout'](
  20. - 'systemctl --full list-units | col -b'
  21. + 'systemctl --full --no-legend --no-pager list-units | col -b'
  22. )
  23. ret = {}
  24. @@ -104,7 +104,7 @@ def _get_all_unit_files():
  25. r')\s+(?P<state>.+)$')
  26. out = __salt__['cmd.run_stdout'](
  27. - 'systemctl --full list-unit-files | col -b'
  28. + 'systemctl --full --no-legend --no-pager list-unit-files | col -b'
  29. )
  30. ret = {}
  31. @@ -195,7 +195,7 @@ def get_all():
  32. salt '*' service.get_all
  33. '''
  34. - return sorted(_get_all_units().keys())
  35. + return sorted(set(_get_all_units().keys() + _get_all_unit_files().keys()))
  36. def available(name):
  37. @@ -209,7 +209,15 @@ def available(name):
  38. salt '*' service.available sshd
  39. '''
  40. - return _canonical_template_unit_name(name) in get_all()
  41. + name = _canonical_template_unit_name(name)
  42. + units = get_all()
  43. + if name in units:
  44. + return True
  45. + elif '@' in name:
  46. + templatename = name[:name.find('@') + 1]
  47. + return templatename in units
  48. + else:
  49. + return False
  50. def missing(name):
  51. @@ -224,7 +232,7 @@ def missing(name):
  52. salt '*' service.missing sshd
  53. '''
  54. - return not _canonical_template_unit_name(name) in get_all()
  55. + return not available(name)
  56. def start(name):
  57. --
  58. 1.9.3