Depend more on rcctl if it is present.

* Make the module support enable/disable of special services like pf via rcctl.
  Idea and method from @jarmani.
* Make the module handle when the user supplied 'arguments' variable does not
  match the current flags in rc.conf.local.
* Update description now that the code tries to use rcctl for everything if it
  is available.
reviewable/pr18780/r1
Patrik Lundin 10 years ago committed by Jonathan Armani
parent 5f37624eb4
commit 924cf20cf8

@ -944,34 +944,48 @@ class FreeBsdService(Service):
class OpenBsdService(Service):
"""
This is the OpenBSD Service manipulation class - it uses /etc/rc.d for
service control. Enabling a service is currently supported if rcctl is present
This is the OpenBSD Service manipulation class - it uses rcctl(8) or
/etc/rc.d scripts for service control. Enabling a service is
only supported if rcctl is present.
"""
platform = 'OpenBSD'
distribution = None
def get_service_tools(self):
rcdir = '/etc/rc.d'
self.enable_cmd = self.module.get_bin_path('rcctl')
rc_script = "%s/%s" % (rcdir, self.name)
if os.path.isfile(rc_script):
self.svc_cmd = rc_script
if self.enable_cmd:
self.svc_cmd = self.enable_cmd
else:
rcdir = '/etc/rc.d'
if not self.svc_cmd:
self.module.fail_json(msg='unable to find rc.d script')
rc_script = "%s/%s" % (rcdir, self.name)
if os.path.isfile(rc_script):
self.svc_cmd = rc_script
self.enable_cmd = self.module.get_bin_path('rcctl')
if not self.svc_cmd:
self.module.fail_json(msg='unable to find svc_cmd')
def get_service_status(self):
rc, stdout, stderr = self.execute_command("%s %s" % (self.svc_cmd, 'check'))
if self.enable_cmd:
rc, stdout, stderr = self.execute_command("%s %s %s" % (self.svc_cmd, 'check', self.name))
else:
rc, stdout, stderr = self.execute_command("%s %s" % (self.svc_cmd, 'check'))
if stderr:
self.module.fail_json(msg=stderr)
if rc == 1:
self.running = False
elif rc == 0:
self.running = True
def service_control(self):
return self.execute_command("%s -f %s" % (self.svc_cmd, self.action))
if self.enable_cmd:
return self.execute_command("%s -f %s %s" % (self.svc_cmd, self.action, self.name))
else:
return self.execute_command("%s -f %s" % (self.svc_cmd, self.action))
def service_enable(self):
if not self.enable_cmd:
@ -982,10 +996,13 @@ class OpenBsdService(Service):
if stderr:
self.module.fail_json(msg=stderr)
current_flags = stdout.rstrip()
if self.enable:
action = "enable %s flags %s" % (self.name, self.arguments)
args = self.arguments
if rc == 0:
action = "enable %s" % (self.name)
if self.arguments or self.arguments != current_flags:
action = action + " flags %s" % (self.arguments)
if rc == 0 and self.arguments == current_flags:
return
else:
action = "disable %s" % self.name

Loading…
Cancel
Save