From c3fc934edbab4258467ee650d4775188cf41fd12 Mon Sep 17 00:00:00 2001 From: Joe Digilio Date: Sat, 22 Jan 2011 10:38:06 -0800 Subject: Support ability to pass parameters to Upstart services --- src/lib/Client/Tools/Upstart.py | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/src/lib/Client/Tools/Upstart.py b/src/lib/Client/Tools/Upstart.py index 113f28d23..b75b0927e 100644 --- a/src/lib/Client/Tools/Upstart.py +++ b/src/lib/Client/Tools/Upstart.py @@ -29,31 +29,38 @@ class Upstart(Bcfg2.Client.Tools.SvcTool): /etc/init/servicename.conf. All we need to do is make sure the service is running when it should be. """ + if entry.get('parameters'): + params = entry.get('parameters') + else: + params = '' + try: - output = self.cmd.run('/usr/sbin/service %s status' % \ - entry.get('name'))[1][0] + output = self.cmd.run('/usr/sbin/service %s status %s' % \ + ( entry.get('name'), params ))[1][0] except IndexError: self.logger.error("Service %s not an Upstart service" % \ entry.get('name')) return False - try: - running = output.split(' ')[1].split('/')[1].startswith('running') - if running: - entry.set('current_status', 'on') - if entry.get('status') == 'off': - status = False - else: - status = True - else: - entry.set('current_status', 'off') - if entry.get('status') == 'on': - status = False - else: - status = True - except IndexError: + + match = re.compile("%s( \(.*\))? (start|stop)/(running|waiting)" %entry.get('name') ).match( output ) + if match == None: # service does not exist entry.set('current_status', 'off') status = False + elif match.group(3) == 'running': + # service is running + entry.set('current_status', 'on') + if entry.get('status') == 'off': + status = False + else: + status = True + else: + # service is not running + entry.set('current_status', 'off') + if entry.get('status') == 'on': + status = False + else: + status = True return status -- cgit v1.2.3-1-g7c22