Skip to content

Commit 2cb245f

Browse files
committed
RcUpdate: Fix detection of running services
Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
1 parent 2d861fb commit 2cb245f

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

src/lib/Bcfg2/Client/Tools/RcUpdate.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ class RcUpdate(Bcfg2.Client.Tools.SvcTool):
1212
__handles__ = [('Service', 'rc-update')]
1313
__req__ = {'Service': ['name', 'status']}
1414

15+
def get_enabled_svcs(self):
16+
"""
17+
Return a list of all enabled services.
18+
"""
19+
return [line.split()[0]
20+
for line in self.cmd.run(['/bin/rc-status',
21+
'-s']).stdout.splitlines()
22+
if 'started' in line]
23+
1524
def VerifyService(self, entry, _):
1625
"""
1726
Verify Service status for entry.
@@ -21,9 +30,12 @@ def VerifyService(self, entry, _):
2130
if entry.get('status') == 'ignore':
2231
return True
2332

33+
# get a list of all started services
34+
allsrv = self.get_enabled_svcs()
35+
2436
# check if service is enabled
25-
result = self.cmd.run(["/sbin/rc-update", "show", "default"])
26-
is_enabled = entry.get("name") in result.stdout
37+
result = self.cmd.run(["/sbin/rc-update", "show", "default"]).stdout
38+
is_enabled = entry.get("name") in result
2739

2840
# check if init script exists
2941
try:
@@ -34,8 +46,7 @@ def VerifyService(self, entry, _):
3446
return False
3547

3648
# check if service is enabled
37-
result = self.cmd.run(self.get_svc_command(entry, "status"))
38-
is_running = "started" in result.stdout
49+
is_running = entry.get('name') in allsrv
3950

4051
if entry.get('status') == 'on' and not (is_enabled and is_running):
4152
entry.set('current_status', 'off')
@@ -70,10 +81,7 @@ def InstallService(self, entry):
7081

7182
def FindExtra(self):
7283
"""Locate extra rc-update services."""
73-
allsrv = [line.split()[0]
74-
for line in self.cmd.run(['/bin/rc-status',
75-
'-s']).stdout.splitlines()
76-
if 'started' in line]
84+
allsrv = self.get_enabled_svcs()
7785
self.logger.debug('Found active services:')
7886
self.logger.debug(allsrv)
7987
specified = [srv.get('name') for srv in self.getSupportedEntries()]

src/lib/Bcfg2/Utils.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,16 @@ class ExecutorResult(object):
108108

109109
def __init__(self, stdout, stderr, retval):
110110
#: The output of the command
111-
self.stdout = stdout
111+
if isinstance(stdout, str):
112+
self.stdout = stdout
113+
else:
114+
self.stdout = stdout.decode('utf-8')
112115

113116
#: The error produced by the command
114-
self.stderr = stderr
117+
if isinstance(stdout, str):
118+
self.stderr = stderr
119+
else:
120+
self.stderr = stderr.decode('utf-8')
115121

116122
#: The return value of the command.
117123
self.retval = retval
@@ -234,6 +240,13 @@ def run(self, command, inputdata=None, shell=False, timeout=None):
234240
for line in inputdata.splitlines():
235241
self.logger.debug('> %s' % line)
236242
(stdout, stderr) = proc.communicate(input=inputdata)
243+
244+
# py3k fixes
245+
if not isinstance(stdout, str):
246+
stdout = stdout.decode('utf-8')
247+
if not isinstance(stderr, str):
248+
stderr = stderr.decode('utf-8')
249+
237250
for line in stdout.splitlines(): # pylint: disable=E1103
238251
self.logger.debug('< %s' % line)
239252
for line in stderr.splitlines(): # pylint: disable=E1103

0 commit comments

Comments
 (0)