Fixup fromcvs/togit conversion
[minix-pkgsrc.git] / sysutils / ansible / patches / patch-library_service
blob6d2f9e9c2f03efd64ba2331f21035dea9b5929d5
1 $NetBSD: patch-library_service,v 1.1 2013/02/26 00:13:00 hubertf Exp $
3 --- library/service.orig        2013-02-09 19:55:06.000000000 +0000
4 +++ library/service
5 @@ -551,6 +551,65 @@ class OpenBsdService(Service):
6          return self.execute_command("%s %s" % (self.svc_cmd, self.action))
7  
8  # ===========================================
9 +# Subclass: NetBSD
11 +class NetBsdService(Service):
12 +    """
13 +    This is the NetBSD Service manipulation class - it uses the /etc/rc.conf
14 +    file for controlling services started at boot, check status and perform
15 +    direct service manipulation. Init scripts in /etc/rcd are used for
16 +    controlling services (start/stop) as well as for controlling the current
17 +    state.
18 +    """
20 +    platform = 'NetBSD'
21 +    distribution = None
23 +    def get_service_tools(self):
24 +        initpaths = [ '/etc/rc.d' ]            # better: $rc_directories - how to get in here? Run: sh -c '. /etc/rc.conf ; echo $rc_directories'
26 +        for initdir in initpaths:
27 +           initscript = "%s/%s" % (initdir,self.name)
28 +           if os.path.isfile(initscript):
29 +               self.svc_initscript = initscript
31 +        if not self.svc_initscript:
32 +            self.module.fail_json(msg='unable to find rc.d script')
34 +    def service_enable(self):
35 +        if self.enable:
36 +            self.rcconf_value = "YES"
37 +        else:
38 +            self.rcconf_value = "NO"
40 +        rcfiles = [ '/etc/rc.conf' ]           # Overkill?
41 +        for rcfile in rcfiles:
42 +            if os.path.isfile(rcfile):
43 +                self.rcconf_file = rcfile
44 +        
45 +        self.rcconf_key = "%s" % self.name
47 +        return self.service_enable_rcconf()
49 +    def get_service_status(self):
50 +        self.svc_cmd = "%s" % self.svc_initscript
51 +        rc, stdout, stderr = self.execute_command("%s %s" % (self.svc_cmd, 'onestatus'))
52 +        if rc == 1:
53 +            self.running = False
54 +        elif rc == 0:
55 +            self.running = True
57 +    def service_control(self):
58 +        if self.action is "start":
59 +            self.action = "onestart"
60 +        if self.action is "stop":
61 +            self.action = "onestop"
63 +        self.svc_cmd = "%s" % self.svc_initscript
64 +        return self.execute_command("%s %s" % (self.svc_cmd, self.action), daemonize=True)
67 +# ===========================================
68  # Main control flow
70  def main():