Skip to content
Browse files

Better detect upstart and sysv services, fix #1915

  • Loading branch information...
1 parent 2be4529 commit 396d404aae8f4d9669de6e6dac4f25314e42ad7a @thatch45 thatch45 committed Aug 30, 2012
Showing with 21 additions and 8 deletions.
  1. +21 −8 salt/modules/upstart.py
View
29 salt/modules/upstart.py
@@ -29,7 +29,7 @@
start on ((((filesystem and runlevel [!06]) and started dbus) and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1 or stopped udev-fallback-graphics)) or runlevel PREVLEVEL=S)
stop on runlevel [016]
-DO NOT use this module on red hat systems, as red hat systems should use the
+DO NOT use this module on Red Hat systems, as Red Hat systems should use the
rh_service module, since red hat systems support chkconfig
'''
# Import Python libs
@@ -100,9 +100,7 @@ def _service_is_sysv(name):
executable, like README or skeleton.
'''
script = '/etc/init.d/{0}'.format(name)
- if not _is_symlink(script):
- return os.access(script, os.X_OK)
- return False
+ return not _service_is_upstart(name) and os.access(script, os.X_OK)
def _sysv_is_disabled(name):
@@ -122,6 +120,23 @@ def _sysv_is_enabled(name):
return not _sysv_is_disabled(name)
+def _iter_service_names():
+ '''
+ Detect all of the service names available to upstart via init configuration
+ files and via classic sysv init scripts
+ '''
+ found = set()
+ for line in glob.glob('/etc/init.d/*'):
+ name = os.path.basename(line)
+ found.add(name)
+ yield name
+ for line in glob.glob('/etc/init/*.conf'):
+ name = os.path.basename(line)[:-5]
+ if name in found:
+ continue
+ yield name
+
+
def get_enabled():
'''
Return the enabled services
@@ -131,8 +146,7 @@ def get_enabled():
salt '*' service.get_enabled
'''
ret = set()
- for line in glob.glob('/etc/init.d/*'):
- name = os.path.basename(line)
+ for name in _iter_service_names():
if _service_is_upstart(name):
if _upstart_is_enabled(name):
ret.add(name)
@@ -152,8 +166,7 @@ def get_disabled():
salt '*' service.get_disabled
'''
ret = set()
- for line in glob.glob('/etc/init.d/*'):
- name = os.path.basename(line)
+ for name in _iter_service_names():
if _service_is_upstart(name):
if _upstart_is_disabled(name):
ret.add(name)

0 comments on commit 396d404

Please sign in to comment.
Something went wrong with that request. Please try again.