diff options
author | Joe Digilio <jgd-github@metajoe.com> | 2011-01-22 10:38:06 -0800 |
---|---|---|
committer | Joe Digilio <jgd-github@metajoe.com> | 2011-01-22 10:38:06 -0800 |
commit | c3fc934edbab4258467ee650d4775188cf41fd12 (patch) | |
tree | a3f0975ed8def420cda36e8f0d3728f23bd0ee2d | |
parent | 3be56c422627ccd1295929c325d2cb29731fbeaf (diff) | |
download | bcfg2-c3fc934edbab4258467ee650d4775188cf41fd12.tar.gz bcfg2-c3fc934edbab4258467ee650d4775188cf41fd12.tar.bz2 bcfg2-c3fc934edbab4258467ee650d4775188cf41fd12.zip |
Support ability to pass parameters to Upstart services
-rw-r--r-- | src/lib/Client/Tools/Upstart.py | 41 |
1 files 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 |