From 3737b08e0d201ab33949f1fc5bc930e0ba2b6fee Mon Sep 17 00:00:00 2001 From: Antoine Jacoutot Date: Thu, 4 Sep 2014 07:41:15 +0200 Subject: [PATCH] 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. --- salt/modules/openbsdrcctl.py | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/salt/modules/openbsdrcctl.py b/salt/modules/openbsdrcctl.py index fe2f964b14..be26b75143 100644 --- a/salt/modules/openbsdrcctl.py +++ b/salt/modules/openbsdrcctl.py @@ -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 salt '*' service.enable 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 + salt '*' service.enabled 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