Skip to content

Commit

Permalink
Load mac_service.py on el capitan, otherwise launchctl.py
Browse files Browse the repository at this point in the history
  • Loading branch information
twangboy committed Jan 28, 2016
1 parent c5f30f4 commit c10bcaf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 37 deletions.
24 changes: 17 additions & 7 deletions salt/modules/launchctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,23 @@ def __virtual__():
'''
Only work on MacOS
'''
if __grains__['os'] == 'MacOS':
if LooseVersion(__grains__['osmajorrelease']) >= '10.10':
global BEFORE_YOSEMITE
BEFORE_YOSEMITE = False
return __virtualname__
return (False, 'launchctl execution module cannot be loaded: '
'only available on MacOS.')
if not salt.utils.is_darwin():
return (False, 'Failed to load the mac_service module:\n'
'Only available on Mac OS X systems.')

if not os.path.exists('/bin/launchctl'):
return (False, 'Failed to load the mac_service module:\n'
'Required binary not found: "/bin/launchctl"')

if LooseVersion(__grains__['osmajorrelease']) >= '10.11':
return (False, 'Failed to load the mac_service module:\n'
'Not available on El Capitan, uses mac_service.py')

if LooseVersion(__grains__['osmajorrelease']) >= '10.10':
global BEFORE_YOSEMITE
BEFORE_YOSEMITE = False

return __virtualname__


def _launchd_paths():
Expand Down
32 changes: 2 additions & 30 deletions salt/modules/mac_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
import salt.ext.six as six
from salt.exceptions import CommandExecutionError

__func_alias__ = {
'reload_': 'reload'
}

log = logging.getLogger(__name__)

# Define the module's virtual name
Expand All @@ -39,9 +35,9 @@ def __virtual__():
return (False, 'Failed to load the mac_service module:\n'
'Required binary not found: "/bin/launchctl"')

if LooseVersion(__grains__['osrelease']) < LooseVersion('10.10'):
if LooseVersion(__grains__['osrelease']) < LooseVersion('10.11'):
return (False, 'Failed to load the mac_service module:\n'
'Requires OS X 10.10 or newer')
'Requires OS X 10.11 or newer')

return __virtualname__

Expand Down Expand Up @@ -345,30 +341,6 @@ def status(name):
return pids


def reload_(service_target):
'''
The linux version of this command refreshes config files by calling service
reload and does not perform a full restart. There is not equivalent on Mac
OS. Therefore this function is the same as ``service.restart``.
:param str service_target: This is a combination of the domain and the label
as defined in the plist file for the service. ``service.get_all`` will
return a list of labels.
:return: True if Successful, False if not
:rtype: bool
CLI Example:
.. code-block:: bash
salt '*' service.reload system/org.cups.cupsd
'''
# Not available in the same way as linux, will perform a restart
return restart(service_target)



def available(name):
'''
Check that the given service is available.
Expand Down

0 comments on commit c10bcaf

Please sign in to comment.