~ubuntu-branches/ubuntu/hardy/bcfg2/hardy-updates

« back to all changes in this revision

Viewing changes to src/lib/Client/Tools/Chkconfig.py

  • Committer: Bazaar Package Importer
  • Author(s): Sami Haahtinen
  • Date: 2006-11-16 22:39:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061116223916-8dtn3t86cz58vg2x
Tags: 0.8.6.1-1
* New Upstream Release
* Replaced faulty if clause in bcfg2.postrm (Closes: #398772)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This is the bcfg2 support for chkconfig
 
2
# $Id: Chkconfig.py 2401 2006-10-06 21:06:16Z desai $
 
3
 
 
4
'''This is chkconfig support'''
 
5
__revision__ = '$Revision: 2401 $'
 
6
 
 
7
import Bcfg2.Client.Tools, Bcfg2.Client.XML
 
8
 
 
9
class Chkconfig(Bcfg2.Client.Tools.SvcTool):
 
10
    '''Chkconfig support for Bcfg2'''
 
11
    __name__ = 'Chkconfig'
 
12
    __execs__ = ['/sbin/chkconfig']
 
13
    __handles__ = [('Service', 'chkconfig')]
 
14
    __req__ = {'Service': ['name', 'status']}
 
15
 
 
16
    def VerifyService(self, entry, _):
 
17
        '''Verify Service status for entry'''
 
18
        try:
 
19
            srvdata = self.cmd.run('/sbin/chkconfig --list %s | grep -v "unknown service"'
 
20
                                   % entry.attrib['name'])[1][0].split()
 
21
        except IndexError:
 
22
            # Ocurrs when no lines are returned (service not installed)
 
23
            entry.set('current_status', 'off')
 
24
            return False
 
25
        if entry.attrib['type'] == 'xinetd':
 
26
            return entry.attrib['status'] == srvdata[1]
 
27
 
 
28
        try:
 
29
            onlevels = [level.split(':')[0] for level in srvdata[1:] if level.split(':')[1] == 'on']
 
30
        except IndexError:
 
31
            onlevels = []
 
32
 
 
33
        # chkconfig/init.d service
 
34
        if entry.get('status') == 'on':
 
35
            status = len(onlevels) > 0
 
36
        else:
 
37
            status = len(onlevels) == 0
 
38
 
 
39
        if not status:
 
40
            if entry.get('status') == 'on':
 
41
                entry.set('current_status', 'off')
 
42
            else:
 
43
                entry.set('current_status', 'on')
 
44
        return status
 
45
 
 
46
    def InstallService(self, entry):
 
47
        '''Install Service entry'''
 
48
        self.cmd.run("/sbin/chkconfig --add %s"%(entry.attrib['name']))
 
49
        self.logger.info("Installing Service %s" % (entry.get('name')))
 
50
        return self.cmd.run("/sbin/chkconfig %s %s" % (entry.get('name'),
 
51
                                                       entry.get('status')))[0] == 0
 
52
 
 
53
    def FindExtra(self):
 
54
        '''Locate extra chkconfig Services'''
 
55
        allsrv = [line.split()[0] for line in \
 
56
                  self.cmd.run("/sbin/chkconfig --list|grep :on")[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='chkconfig', name=name) \
 
61
                for name in allsrv if name not in specified]
 
62