Adds support for nested upstart scripts in the form of subfolder/service. This is implemented via an os.walk through the /etc/init folder, rather than the previous glob for *.conf method.

Fixes #26478 - nested upstart services are not supported
This commit is contained in:
Chris Fane 2015-08-20 10:59:20 +01:00
parent 0cf9f11aa5
commit e00a98fd37

View File

@ -45,6 +45,7 @@ import glob
import os
import re
import itertools
import fnmatch
# Import salt libs
import salt.utils
@ -226,11 +227,24 @@ def _iter_service_names():
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
# This walk method supports nested services as per the init man page
# definition 'For example a configuration file /etc/init/rc-sysinit.conf
# is named rc-sysinit, while a configuration file /etc/init/net/apache.conf
# is named net/apache'
init_root = '/etc/init/'
for root, dirnames, filenames in os.walk(init_root):
relpath = os.path.relpath(root, init_root)
for filename in fnmatch.filter(filenames, '*.conf'):
if relpath == '.':
# service is defined in the root, no need to append prefix.
name = filename[:-5]
else:
# service is nested, append its relative path prefix.
name = os.path.join(relpath, filename[:-5])
if name in found:
continue
yield name
def get_enabled():