From eee7a1c12e7924fd50ee63ab9e3f1a0c8b5e2c09 Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Wed, 21 Apr 2010 10:46:39 -0500 Subject: Upstart: Fix traceback for services that don't exist Signed-off-by: Sol Jerome --- src/lib/Client/Tools/Upstart.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/lib/Client/Tools/Upstart.py b/src/lib/Client/Tools/Upstart.py index 43a51fd79..1fc80a1db 100644 --- a/src/lib/Client/Tools/Upstart.py +++ b/src/lib/Client/Tools/Upstart.py @@ -31,18 +31,24 @@ class Upstart(Bcfg2.Client.Tools.SvcTool): ''' output = self.cmd.run('/usr/sbin/service %s status' % \ entry.get('name'))[1][0] - if output.split(' ')[1].split('/')[1].startswith('running'): - entry.set('current_status', 'on') - if entry.get('status') == 'off': - status = 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: - status = True - else: + entry.set('current_status', 'off') + if entry.get('status') == 'on': + status = False + else: + status = True + except IndexError: + # service does not exist entry.set('current_status', 'off') - if entry.get('status') == 'on': - status = False - else: - status = True + status = False return status -- cgit v1.2.3-1-g7c22