diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2006-10-06 21:06:16 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2006-10-06 21:06:16 +0000 |
commit | 7beb2f08d8dab26d9fe34235c91c1b2a7a2794bd (patch) | |
tree | 92510fa0a9bb4de4c589b8a2f406aa097e0ab3d2 /src/lib/Client/Tools/Chkconfig.py | |
parent | 53a983ba616d1c2292e1f4117084f85a1db9454f (diff) | |
download | bcfg2-7beb2f08d8dab26d9fe34235c91c1b2a7a2794bd.tar.gz bcfg2-7beb2f08d8dab26d9fe34235c91c1b2a7a2794bd.tar.bz2 bcfg2-7beb2f08d8dab26d9fe34235c91c1b2a7a2794bd.zip |
Merge of the client/refactor branch (revisions r2218-r2400)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2401 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Client/Tools/Chkconfig.py')
-rw-r--r-- | src/lib/Client/Tools/Chkconfig.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/lib/Client/Tools/Chkconfig.py b/src/lib/Client/Tools/Chkconfig.py new file mode 100644 index 000000000..a1c1160c9 --- /dev/null +++ b/src/lib/Client/Tools/Chkconfig.py @@ -0,0 +1,62 @@ +# This is the bcfg2 support for chkconfig +# $Id$ + +'''This is chkconfig support''' +__revision__ = '$Revision$' + +import Bcfg2.Client.Tools, Bcfg2.Client.XML + +class Chkconfig(Bcfg2.Client.Tools.SvcTool): + '''Chkconfig support for Bcfg2''' + __name__ = 'Chkconfig' + __execs__ = ['/sbin/chkconfig'] + __handles__ = [('Service', 'chkconfig')] + __req__ = {'Service': ['name', 'status']} + + def VerifyService(self, entry, _): + '''Verify Service status for entry''' + try: + srvdata = self.cmd.run('/sbin/chkconfig --list %s | grep -v "unknown service"' + % entry.attrib['name'])[1][0].split() + except IndexError: + # Ocurrs when no lines are returned (service not installed) + entry.set('current_status', 'off') + return False + if entry.attrib['type'] == 'xinetd': + return entry.attrib['status'] == srvdata[1] + + try: + onlevels = [level.split(':')[0] for level in srvdata[1:] if level.split(':')[1] == 'on'] + except IndexError: + onlevels = [] + + # chkconfig/init.d service + if entry.get('status') == 'on': + status = len(onlevels) > 0 + else: + status = len(onlevels) == 0 + + if not status: + if entry.get('status') == 'on': + entry.set('current_status', 'off') + else: + entry.set('current_status', 'on') + return status + + def InstallService(self, entry): + '''Install Service entry''' + self.cmd.run("/sbin/chkconfig --add %s"%(entry.attrib['name'])) + self.logger.info("Installing Service %s" % (entry.get('name'))) + return self.cmd.run("/sbin/chkconfig %s %s" % (entry.get('name'), + entry.get('status')))[0] == 0 + + def FindExtra(self): + '''Locate extra chkconfig Services''' + allsrv = [line.split()[0] for line in \ + self.cmd.run("/sbin/chkconfig --list|grep :on")[1]] + self.logger.debug('Found active services:') + self.logger.debug(allsrv) + specified = [srv.get('name') for srv in self.getSupportedEntries()] + return [Bcfg2.Client.XML.Element('Service', type='chkconfig', name=name) \ + for name in allsrv if name not in specified] + |