From 2b34d93eb2c4d3f29fc4f4ebb1171f9207f70a43 Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Fri, 1 Dec 2006 20:47:09 +0000 Subject: Initial Gentoo support (from Michael Jinks) git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2561 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Client/Tools/RcUpdate.py | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/lib/Client/Tools/RcUpdate.py (limited to 'src/lib/Client/Tools/RcUpdate.py') diff --git a/src/lib/Client/Tools/RcUpdate.py b/src/lib/Client/Tools/RcUpdate.py new file mode 100644 index 000000000..7e2ea73be --- /dev/null +++ b/src/lib/Client/Tools/RcUpdate.py @@ -0,0 +1,58 @@ +'''This is rc-update support''' +__revision__ = '$Revision: $' + +import Bcfg2.Client.Tools, Bcfg2.Client.XML, commands, os + +class RcUpdate(Bcfg2.Client.Tools.SvcTool): + '''RcUpdate support for Bcfg2''' + __name__ = 'RcUpdate' + __execs__ = ['/sbin/rc-update', '/bin/rc-status'] + __handles__ = [('Service', 'rc-update')] + __req__ = {'Service': ['name', 'status']} + + def VerifyService(self, entry, _): + '''Verify Service status for entry. Assumes we run in the "default" runlevel.''' + # mrj - i think this should be: + # rc = self.cmd.run('/bin/rc-status | grep %s | grep started"' % entry.attrib['name']) + # ...but as i can't figure out a way to test that right now, i'll do the one + # that works in python's interactive interpreter. + rc = commands.getoutput('/bin/rc-status | grep %s | grep started' % \ + entry.get('name')) + status = len(rc) > 0 + + if not status: + # service is off + if entry.get('status') == 'on': + # we want it on, it's not + entry.set('current_status', 'off') + else: + # we want it off, it's not + entry.set('current_status', 'on') + return status + + def InstallService(self, entry): + '''Install Service entry''' + self.logger.info("Installing Service %s" % (entry.get('name'))) + try: + os.stat('/etc/init.d/%s' % entry.get('name')) + except OSError: + self.logger.debug("Init script for service %s does not exist" % entry.get('name')) + return False + + if entry.get('status') == 'off': + self.cmd.run("/etc/init.d/%s stop" % (entry.get('name'))) + cmdrc = self.cmd.run("/sbin/rc-update del %s default" % (entry.get('name'))) + else: + cmdrc = self.cmd.run("/sbin/rc-update add %s default" % entry.get('name'))[0] + return cmdrc == 0 + + def FindExtra(self): + '''Locate extra rc-update Services''' + allsrv = [line.split()[0] for line in \ + self.cmd.run("/bin/rc-status | grep started")[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='rc-update', name=name) \ + for name in allsrv if name not in specified] + -- cgit v1.2.3-1-g7c22