summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorSol Jerome <solj@ices.utexas.edu>2010-03-26 14:05:56 +0000
committerSol Jerome <solj@ices.utexas.edu>2010-03-26 09:07:29 -0500
commit4fa2c7a05060dfda184e98d55c1d00ae53840348 (patch)
tree7e46ce9ebeb32c5af6165e58db791bb0c78fbcc8 /src/lib
parent8999c249ccc3d93f08060fbfb0b7598e7e15cfda (diff)
downloadbcfg2-4fa2c7a05060dfda184e98d55c1d00ae53840348.tar.gz
bcfg2-4fa2c7a05060dfda184e98d55c1d00ae53840348.tar.bz2
bcfg2-4fa2c7a05060dfda184e98d55c1d00ae53840348.zip
Reworked RcUpdate.py. VerifyService now checks if running services are
enabled. InstallService now respects supervised mode. git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5795 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Client/Tools/RcUpdate.py95
1 files changed, 61 insertions, 34 deletions
diff --git a/src/lib/Client/Tools/RcUpdate.py b/src/lib/Client/Tools/RcUpdate.py
index 58beb56a4..5b64b2af0 100644
--- a/src/lib/Client/Tools/RcUpdate.py
+++ b/src/lib/Client/Tools/RcUpdate.py
@@ -17,53 +17,80 @@ class RcUpdate(Bcfg2.Client.Tools.SvcTool):
Verify Service status for entry.
Assumes we run in the "default" runlevel.
'''
- rc, output = self.cmd.run('/bin/rc-status -s | grep %s | grep started' % \
- entry.attrib['name'])
- status = (rc == 0)
+ # check if init script exists
+ 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
+
+ # check is service is enabled
+ cmd = '/etc/init.d/%s status | grep started'
+ rc = self.cmd.run(cmd % entry.get('name'))[0]
+ is_enabled = (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, check if it is
- rc, output = self.cmd.run('/bin/rc-status -u | grep %s | grep stopped' % \
- entry.get('name'))
- status = (rc == 0)
- if not status:
- # it's not off and should be
- entry.set('current_status', 'on')
+ if entry.get('mode', 'default') == 'supervised':
+ # check is service is enabled
+ cmd = '/bin/rc-status -s | grep %s | grep started'
+ rc = self.cmd.run(cmd % entry.attrib['name'])[0]
+ is_running = (rc == 0)
else:
- if entry.get('status') == 'off':
- # we want it off, it's not
- entry.set('current_status', 'on')
- return False;
- return status
+ # we don't care
+ is_running = is_enabled
+
+ if entry.get('status') == 'on' and not (is_enabled and is_running):
+ entry.set('current_status', 'off')
+ return False
+
+ elif entry.get('status') == 'off' and (is_enabled or is_running):
+ entry.set('current_status', 'on')
+ return False
+
+ return True
def InstallService(self, entry):
- '''Install Service entry'''
- self.logger.info("Installing Service %s" % (entry.get('name')))
+ '''
+ Install Service entry
+ In supervised mode we also take care it's (not) running
+ '''
+ # check if init script exists
try:
os.stat('/etc/init.d/%s' % entry.get('name'))
except OSError:
- self.logger.debug("Init script for service %s does not exist" %
+ 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
+ self.logger.info("Installing Service %s" % entry.get('name'))
+ if entry.get('status') == 'on':
+ # make sure it's enabled
+ cmd = '/sbin/rc-update add %s default'
+ rc = self.cmd.run(cmd % entry.get('name'))[0]
+ status = (rc == 0)
+ if entry.get('mode', 'default') == 'supervised':
+ # make sure it's running
+ cmd = '/etc/init.d/%s start'
+ rc = self.cmd.run(cmd % entry.get('name'))[0]
+ status &= (rc == 0)
+
+ elif entry.get('status') == 'off':
+ # make sure it's disabled
+ cmd = '/sbin/rc-update del %s default'
+ rc = self.cmd.run(cmd % entry.get('name'))[0]
+ status = (rc == 0)
+ if entry.get('mode', 'default') == 'supervised':
+ # make sure it's not running
+ cmd = '/etc/init.d/%s stop'
+ rc = self.cmd.run(cmd % entry.get('name'))[0]
+ status &= (rc == 0)
+
+ return status
def FindExtra(self):
'''Locate extra rc-update Services'''
- allsrv = [line.split()[0] for line in \
- self.cmd.run("/bin/rc-status -s | grep started")[1]]
+ cmd = '/bin/rc-status -s | grep started'
+ allsrv = [line.split()[0] for line in self.cmd.run(cmd)[1]]
self.logger.debug('Found active services:')
self.logger.debug(allsrv)
specified = [srv.get('name') for srv in self.getSupportedEntries()]