Skip to content

Commit

Permalink
SmartOS/Solaris: fix SMF service management
Browse files Browse the repository at this point in the history
fixes saltstack#10702

The functions previously named get_enabled and get_disabled
actually only queried what services were running or not

This caused breakages where a state that both requested
"enabled" and "running" could cause salt to start the
service which would make it appear in the list of
enabled services, but not actually get enabled
and thus not actually come back up on reboot

Those functions have been renamed to get_running
and get_stopped

An accurate enabled function has been written
which queries the true property that determines
if a service will come up at boot
and disabled returns its negation.

New get_enabled and get_disabled functions have
also been written which accurately return the
list of enabled or disabled services
Those functions return full FMRIs (rather than the
much shorter 'SVC' column) because that's how
SMF actually works internally.
  • Loading branch information
nshalman committed Feb 25, 2014
1 parent 125afd7 commit e290785
Showing 1 changed file with 65 additions and 11 deletions.
76 changes: 65 additions & 11 deletions salt/modules/smf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,34 @@ def __virtual__():
return False


def get_enabled():
def _get_enabled_disabled(enabled_prop="true"):
'''
Return the enabled services
DRY: Get all service FMRIs and their enabled property
'''
ret = set()
cmd = '/usr/bin/svcprop -c -p general/enabled "*"'
lines = __salt__['cmd.run_stdout'](cmd).splitlines()
for line in lines:
comps = line.split()
if not comps:
continue
if comps[2] == enabled_prop:
ret.add(comps[0].split("/:properties")[0])
return sorted(ret)


def get_running():
'''
Return the running services
CLI Example:
.. code-block:: bash
salt '*' service.get_enabled
salt '*' service.get_running
'''
ret = set()
cmd = 'svcs -H -o SVC,STATE -s SVC'
cmd = '/usr/bin/svcs -H -o SVC,STATE -s SVC'
lines = __salt__['cmd.run'](cmd).splitlines()
for line in lines:
comps = line.split()
Expand All @@ -46,18 +62,18 @@ def get_enabled():
return sorted(ret)


def get_disabled():
def get_stopped():
'''
Return the disabled services
Return the stopped services
CLI Example:
.. code-block:: bash
salt '*' service.get_disabled
salt '*' service.get_stopped
'''
ret = set()
cmd = 'svcs -aH -o SVC,STATE -s SVC'
cmd = '/usr/bin/svcs -aH -o SVC,STATE -s SVC'
lines = __salt__['cmd.run'](cmd).splitlines()
for line in lines:
comps = line.split()
Expand Down Expand Up @@ -108,7 +124,7 @@ def get_all():
salt '*' service.get_all
'''
ret = set()
cmd = 'svcs -aH -o SVC,STATE -s SVC'
cmd = '/usr/bin/svcs -aH -o SVC,STATE -s SVC'
lines = __salt__['cmd.run'](cmd).splitlines()
for line in lines:
comps = line.split()
Expand Down Expand Up @@ -249,7 +265,17 @@ def enabled(name):
salt '*' service.enabled <service name>
'''
return name in get_enabled()
# The property that reveals whether a service is enabled
# can only be queried using the full FMRI
# We extract the FMRI and then do the query
fmri_cmd = '/usr/bin/svcs -H -o FMRI {0}'.format(name)
fmri = __salt__['cmd.run'](fmri_cmd)
cmd = '/usr/sbin/svccfg -s {0} listprop general/enabled'.format(fmri)
comps = __salt__['cmd.run'](cmd).split()
if comps[2] == 'true':
return True
else:
return False


def disabled(name):
Expand All @@ -262,4 +288,32 @@ def disabled(name):
salt '*' service.disabled <service name>
'''
return name in get_disabled()
return not enabled(name)


def get_enabled():
'''
Return the enabled services
CLI Example:
.. code-block:: bash
salt '*' service.get_enabled
'''
# Note that this returns the full FMRI
return _get_enabled_disabled("true")


def get_disabled():
'''
Return the disabled services
CLI Example:
.. code-block:: bash
salt '*' service.get_disabled
'''
# Note that this returns the full FMRI
return _get_enabled_disabled("false")

0 comments on commit e290785

Please sign in to comment.