openbsdrcctl: extend enabled() to check flags

On OpenBSD, it's possible to define particular flags a daemon should be
enabled with (ala /etc/sysconfig/... in RedHat). To make sure the flags
are properly updated when changed (in pillars or states), we return a
service as "disabled" if the currently configured flags do not match the
provided ones; this ensures /etc/rc.conf.local is always in sync.
This commit is contained in:
Antoine Jacoutot 2014-09-04 07:41:15 +02:00
parent 3c2d2feaf8
commit 3737b08e0d

View File

@ -40,6 +40,16 @@ def _cmd():
return rcctl
def _get_flags(**kwargs):
'''
Return the configured service flags.
'''
flags = kwargs.get('flags', \
__salt__['config.option']('service.flags', \
default=''))
return flags
def available(name):
'''
Return True if the named service is available.
@ -216,15 +226,8 @@ def enable(name, **kwargs):
salt '*' service.enable <service name>
salt '*' service.enable <service name> flags=<flags>
'''
flags = kwargs.get('flags',
__salt__['config.option']('service.flags',
default=''))
if not flags:
cmd = '{0} enable {1}'.format(_cmd(), name)
else:
cmd = '{0} enable {1} flags {2}'.format(_cmd(), name, flags)
flags = _get_flags(**kwargs)
cmd = '{0} enable {1} flags {2}'.format(_cmd(), name, flags)
return not __salt__['cmd.retcode'](cmd)
@ -258,7 +261,8 @@ def disabled(name):
def enabled(name, **kwargs):
'''
Return True if the named service is enabled at boot, False otherwise.
Return True if the named service is enabled at boot and the provided
flags match the configured ones (if any). Return False otherwise.
name
Service name
@ -268,6 +272,15 @@ def enabled(name, **kwargs):
.. code-block:: bash
salt '*' service.enabled <service name>
salt '*' service.enabled <service name> flags=<flags>
'''
cmd = '{0} status {1}'.format(_cmd(), name)
return not __salt__['cmd.retcode'](cmd)
if not __salt__['cmd.retcode'](cmd):
# also consider a service disabled if the current flags are different
# than the configured ones so we have a chance to update them
flags = _get_flags(**kwargs)
cur_flags = __salt__['cmd.run_stdout']('{0} status {1}'.format(_cmd(), name))
if format(flags) == format(cur_flags):
return True
return False