Merge pull request #27680 from rallytime/bp-27535

Back-port #27535 to 2015.5
This commit is contained in:
Colton Myers 2015-10-05 15:17:10 -06:00
commit 23da0d316a
2 changed files with 59 additions and 1 deletions

View file

@ -15,10 +15,13 @@ so it can be used to maintain services using the ``provider`` argument:
from __future__ import absolute_import
# Import python libs
import logging
import os
import os.path
import re
# Import salt libs
import salt.utils
from salt.exceptions import CommandExecutionError
# Function alias to not shadow built-ins.
@ -26,6 +29,8 @@ __func_alias__ = {
'reload_': 'reload'
}
log = logging.getLogger(__name__)
VALID_SERVICE_DIRS = [
'/service',
'/var/service',
@ -38,6 +43,12 @@ for service_dir in VALID_SERVICE_DIRS:
break
def __virtual__():
# Ensure that daemontools is installed properly.
BINS = frozenset(('svc', 'supervise', 'svok'))
return all(salt.utils.which(b) for b in BINS)
def _service_path(name):
'''
build service path
@ -201,3 +212,50 @@ def get_all():
raise CommandExecutionError("Could not find service directory.")
#- List all daemontools services in
return sorted(os.listdir(SERVICE_DIR))
def enabled(name, **kwargs):
'''
Return True if the named service is enabled, false otherwise
A service is considered enabled if in your service directory:
- an executable ./run file exist
- a file named "down" does not exist
.. versionadded:: 2015.5.7
name
Service name
CLI Example:
.. code-block:: bash
salt '*' daemontools.enabled <service name>
'''
if not available(name):
log.error('Service {0} not found'.format(name))
return False
run_file = os.path.join(SERVICE_DIR, name, 'run')
down_file = os.path.join(SERVICE_DIR, name, 'down')
return (
os.path.isfile(run_file) and
os.access(run_file, os.X_OK) and not
os.path.isfile(down_file)
)
def disabled(name):
'''
Return True if the named service is enabled, false otherwise
.. versionadded:: 2015.5.6
CLI Example:
.. code-block:: bash
salt '*' daemontools.disabled <service name>
'''
return not enabled(name)

View file

@ -25,7 +25,7 @@ __virtualname__ = 'service'
def __virtual__():
'''
Only work on systems which default to systemd
Only work on FreeBSD
'''
# Disable on these platforms, specific service modules exist:
if __grains__['os'] == 'FreeBSD':