[Pkg-salt-team] Bug#770174: salt-common: service module doesn't work for init scripts
Julien Cristau
julien.cristau at logilab.fr
Wed Nov 19 11:43:06 UTC 2014
Package: salt-common
Version: 2014.1.13+ds-1
Severity: grave
Tags: patch upstream fixed-upstream
Justification: renders package unusable
Hi,
when booting with systemd, the service module is provided by
salt/modules/systemd.py, which only considers native systemd units in
its get_all function, not services provided by init scripts. This
breaks the service state.
The fix is in upstream commits
90bece1faa1862465e97f7caf262c65cd84583ff and
968b26f45351d790a9fa2afd9bbd6c5bb31f13d5, so basically:
diff --git a/salt/modules/systemd.py b/salt/modules/systemd.py
--- a/salt/modules/systemd.py
+++ b/salt/modules/systemd.py
@@ -72,6 +74,28 @@ def _systemctl_cmd(action, name):
return 'systemctl {0} {1}'.format(action, _canonical_unit_name(name))
+def _get_all_units():
+ '''
+ Get all units and their state. Units ending in .service
+ are normalized so that they can be referenced without a type suffix.
+ '''
+ rexp = re.compile(r'(?m)^(?P<name>.+)\.(?P<type>' +
+ '|'.join(VALID_UNIT_TYPES) +
+ r')\s+loaded\s+(?P<active>[^\s]+)')
+
+ out = __salt__['cmd.run_stdout'](
+ 'systemctl --all --full --no-legend --no-pager list-units | col -b'
+ )
+
+ ret = {}
+ for match in rexp.finditer(out):
+ name = match.group('name')
+ if match.group('type') != 'service':
+ name += '.' + match.group('type')
+ ret[name] = match.group('active')
+ return ret
+
+
def _get_all_unit_files():
'''
Get all unit files and their state. Unit files ending in .service
@@ -173,7 +197,7 @@ def get_all():
salt '*' service.get_all
'''
- return sorted(_get_all_unit_files().keys())
+ return sorted(set(_get_all_units().keys() + _get_all_unit_files().keys()))
def available(name):
There are a few other fixes in that file that might be worth
considering, but at least the above is I think necessary for salt to
be in decent shape for jessie.
Cheers,
Julien
--
Julien Cristau <julien.cristau at logilab.fr>
Logilab http://www.logilab.fr/
Informatique scientifique & gestion de connaissances
More information about the pkg-salt-team
mailing list