From 18d9fc581d61014c869c681fcbc40d572d5c182f Mon Sep 17 00:00:00 2001 From: Hubert Feyrer Date: Wed, 13 Feb 2013 22:07:31 +0100 Subject: [PATCH] Add support for NetBSD. Tested on NetBSD 6.0/i386. --- library/service | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/library/service b/library/service index 59cd61d8f1..adac3ba4b9 100644 --- a/library/service +++ b/library/service @@ -551,6 +551,65 @@ class OpenBsdService(Service): def service_control(self): return self.execute_command("%s %s" % (self.svc_cmd, self.action)) +# =========================================== +# Subclass: NetBSD + +class NetBsdService(Service): + """ + This is the NetBSD Service manipulation class - it uses the /etc/rc.conf + file for controlling services started at boot, check status and perform + direct service manipulation. Init scripts in /etc/rcd are used for + controlling services (start/stop) as well as for controlling the current + state. + """ + + platform = 'NetBSD' + distribution = None + + def get_service_tools(self): + initpaths = [ '/etc/rc.d' ] # better: $rc_directories - how to get in here? Run: sh -c '. /etc/rc.conf ; echo $rc_directories' + + for initdir in initpaths: + initscript = "%s/%s" % (initdir,self.name) + if os.path.isfile(initscript): + self.svc_initscript = initscript + + if not self.svc_initscript: + self.module.fail_json(msg='unable to find rc.d script') + + def service_enable(self): + if self.enable: + self.rcconf_value = "YES" + else: + self.rcconf_value = "NO" + + rcfiles = [ '/etc/rc.conf' ] # Overkill? + for rcfile in rcfiles: + if os.path.isfile(rcfile): + self.rcconf_file = rcfile + + self.rcconf_key = "%s" % self.name + + return self.service_enable_rcconf() + + def get_service_status(self): + self.svc_cmd = "%s" % self.svc_initscript + rc, stdout, stderr = self.execute_command("%s %s" % (self.svc_cmd, 'onestatus')) + if rc == 1: + self.running = False + elif rc == 0: + self.running = True + + def service_control(self): + if self.action is "start": + self.action = "onestart" + if self.action is "stop": + self.action = "onestop" + + self.svc_cmd = "%s" % self.svc_initscript + return self.execute_command("%s %s" % (self.svc_cmd, self.action)) + + # =========================================== # Main control flow