From 1b973907658374d146f7a4126a6b9979171db326 Mon Sep 17 00:00:00 2001 From: Jonathan Armani Date: Wed, 27 Aug 2014 22:26:47 +0200 Subject: [PATCH] Add enable / disable of services for OpenBSD if rcctl is present --- system/service.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/system/service.py b/system/service.py index b235ee25c57..d708a848bd3 100644 --- a/system/service.py +++ b/system/service.py @@ -945,9 +945,7 @@ 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 not supported because the - _flags variable is not boolean, you should supply a rc.conf.local - file in some other way. + service control. Enabling a service is currently supported if rcctl is present """ platform = 'OpenBSD' @@ -963,6 +961,8 @@ class OpenBsdService(Service): 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') + def get_service_status(self): rc, stdout, stderr = self.execute_command("%s %s" % (self.svc_cmd, 'check')) if rc == 1: @@ -971,7 +971,27 @@ class OpenBsdService(Service): self.running = True def service_control(self): - return self.execute_command("%s %s" % (self.svc_cmd, self.action)) + return self.execute_command("%s -f %s" % (self.svc_cmd, self.action)) + + def service_enable(self): + if not self.enable_cmd: + return super(OpenBsdService, self).service_enable() + + rc, stdout, stderr = self.execute_command("%s %s %s" % (self.enable_cmd, 'status', self.name)) + + if self.enable: + action = "enable %s flags %s" % (self.name, self.arguments) + args = self.arguments + if rc == 0: + return + else: + action = "disable %s" % self.name + if rc == 1: + return + + # XXX check rc ? + rc, stdout, stderr = self.execute_command("%s %s" % (self.enable_cmd, action)) + self.changed = True # =========================================== # Subclass: NetBSD