Merge pull request #2466 from sfromm/issue2449

Limit scope of arguments to service_control() in service module
reviewable/pr18780/r1
Michael DeHaan 12 years ago
commit 9d06976273

@ -509,40 +509,41 @@ class LinuxService(Service):
# Decide what command to run # Decide what command to run
svc_cmd = '' svc_cmd = ''
arguments = self.arguments
if self.svc_cmd: if self.svc_cmd:
if not self.svc_cmd.endswith("systemctl"): if not self.svc_cmd.endswith("systemctl"):
# SysV or systemd take the form <cmd> <name> <action> # SysV take the form <cmd> <name> <action>
svc_cmd = "%s %s" % (self.svc_cmd, self.name) svc_cmd = "%s %s" % (self.svc_cmd, self.name)
else: else:
# systemd commands take the form <cmd> <action> <name> # systemd commands take the form <cmd> <action> <name>
svc_cmd = self.svc_cmd svc_cmd = self.svc_cmd
self.arguments = "%s %s" % (self.name, self.arguments) arguments = "%s %s" % (self.name, arguments)
elif self.svc_initscript: elif self.svc_initscript:
# upstart # upstart
svc_cmd = "%s" % self.svc_initscript svc_cmd = "%s" % self.svc_initscript
if self.action is not "restart": if self.action is not "restart":
if svc_cmd != '': if svc_cmd != '':
# upstart # upstart or systemd
rc_state, stdout, stderr = self.execute_command("%s %s %s" % (svc_cmd, self.action, self.arguments), daemonize=True) rc_state, stdout, stderr = self.execute_command("%s %s %s" % (svc_cmd, self.action, arguments), daemonize=True)
else: else:
# SysV or systemd # SysV
rc_state, stdout, stderr = self.execute_command("%s %s %s" % (self.action, self.name, self.arguments), daemonize=True) rc_state, stdout, stderr = self.execute_command("%s %s %s" % (self.action, self.name, arguments), daemonize=True)
else: else:
# not all services support restart. Do it the hard way. # not all services support restart. Do it the hard way.
if svc_cmd != '': if svc_cmd != '':
# upstart # upstart or systemd
rc1, stdout1, stderr1 = self.execute_command("%s %s %s" % (svc_cmd, 'stop', self.arguments), daemonize=True) rc1, stdout1, stderr1 = self.execute_command("%s %s %s" % (svc_cmd, 'stop', arguments), daemonize=True)
else: else:
# SysV or systemd # SysV
rc1, stdout1, stderr1 = self.execute_command("%s %s %s" % ('stop', self.name, self.arguments), daemonize=True) rc1, stdout1, stderr1 = self.execute_command("%s %s %s" % ('stop', self.name, arguments), daemonize=True)
if svc_cmd != '': if svc_cmd != '':
# upstart # upstart or systemd
rc2, stdout2, stderr2 = self.execute_command("%s %s %s" % (svc_cmd, 'start', self.arguments), daemonize=True) rc2, stdout2, stderr2 = self.execute_command("%s %s %s" % (svc_cmd, 'start', arguments), daemonize=True)
else: else:
# SysV or systemd # SysV
rc2, stdout2, stderr2 = self.execute_command("%s %s %s" % ('start', self.name, self.arguments), daemonize=True) rc2, stdout2, stderr2 = self.execute_command("%s %s %s" % ('start', self.name, arguments), daemonize=True)
# merge return information # merge return information
if rc1 != 0 and rc2 == 0: if rc1 != 0 and rc2 == 0:

Loading…
Cancel
Save