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.
This commit is contained in:
Patrik Lundin 2014-09-06 19:48:14 +02:00 committed by Jonathan Armani
parent 5f37624eb4
commit 924cf20cf8

View file

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