root/trunk/bcfg2/src/lib/Client/Tools/RcUpdate.py

Revision 5558, 2.2 KB (checked in by solj, 2 weeks ago)

RcUpdate?: Fix final regression caused by [5178] (Patch from Thorsten Lockert)

Resolves ticket #790.

Signed-off-by: Sol Jerome <solj@…>

  • Property svn:keywords set to Revision
Line 
1'''This is rc-update support'''
2__revision__ = '$Revision$'
3
4import os
5import Bcfg2.Client.Tools
6import Bcfg2.Client.XML
7
8class RcUpdate(Bcfg2.Client.Tools.SvcTool):
9    '''RcUpdate support for Bcfg2'''
10    name = 'RcUpdate'
11    __execs__ = ['/sbin/rc-update', '/bin/rc-status']
12    __handles__ = [('Service', 'rc-update')]
13    __req__ = {'Service': ['name', 'status']}
14
15    def VerifyService(self, entry, _):
16        '''
17        Verify Service status for entry.
18        Assumes we run in the "default" runlevel.
19        '''
20        rc, output = self.cmd.run('/bin/rc-status -s | grep %s | grep started' % \
21                                  entry.attrib['name'])
22        status = (rc == 0)
23
24        if not status:
25            # service is off
26            if entry.get('status') == 'on':
27                # we want it on, it's not
28                entry.set('current_status', 'off')
29            else:
30                # we want it off, it's not
31                entry.set('current_status', 'on')
32        return status
33
34    def InstallService(self, entry):
35        '''Install Service entry'''
36        self.logger.info("Installing Service %s" % (entry.get('name')))
37        try:
38            os.stat('/etc/init.d/%s' % entry.get('name'))
39        except OSError:
40            self.logger.debug("Init script for service %s does not exist" %
41                              entry.get('name'))
42            return False
43
44        if entry.get('status') == 'off':
45            self.cmd.run("/etc/init.d/%s stop" % (entry.get('name')))
46            cmdrc = self.cmd.run("/sbin/rc-update del %s default" %
47                                (entry.get('name')))
48        else:
49            cmdrc = self.cmd.run("/sbin/rc-update add %s default" %
50                                 entry.get('name'))[0]
51        return cmdrc == 0
52
53    def FindExtra(self):
54        '''Locate extra rc-update Services'''
55        allsrv = [line.split()[0] for line in \
56                  self.cmd.run("/bin/rc-status -s | grep started")[1]]
57        self.logger.debug('Found active services:')
58        self.logger.debug(allsrv)
59        specified = [srv.get('name') for srv in self.getSupportedEntries()]
60        return [Bcfg2.Client.XML.Element('Service', type='rc-update', name=name) \
61                for name in allsrv if name not in specified]
Note: See TracBrowser for help on using the browser.