From 5194a71a700149249f9c15f240a7d76ca84f84e1 Mon Sep 17 00:00:00 2001 From: Stephen Fromm Date: Wed, 20 Mar 2013 08:50:36 -0700 Subject: [PATCH] Limit scope of arguments to service_control() in service module This fixes handling of arguments (module argument) in service_control(). It is now locally scoped such that modifications to it, in the case of a systemd host, do not later impact subsequent calls to service_control(). See issue #2449. Without patch: ansible-service[6177]: Command /usr/bin/systemctl stop cups cups , daemonize True With patch: ansible-service[6475]: Command /usr/bin/systemctl start cups , daemonize True I also updated the comments to reflect the case where systemd is really being called. --- library/service | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/library/service b/library/service index 278cc77a915..14b231a2ef9 100644 --- a/library/service +++ b/library/service @@ -509,40 +509,41 @@ class LinuxService(Service): # Decide what command to run svc_cmd = '' + arguments = self.arguments if self.svc_cmd: if not self.svc_cmd.endswith("systemctl"): - # SysV or systemd take the form + # SysV take the form svc_cmd = "%s %s" % (self.svc_cmd, self.name) else: # systemd commands take the form svc_cmd = self.svc_cmd - self.arguments = "%s %s" % (self.name, self.arguments) + arguments = "%s %s" % (self.name, arguments) elif self.svc_initscript: # upstart svc_cmd = "%s" % self.svc_initscript if self.action is not "restart": if svc_cmd != '': - # upstart - rc_state, stdout, stderr = self.execute_command("%s %s %s" % (svc_cmd, self.action, self.arguments), daemonize=True) + # upstart or systemd + rc_state, stdout, stderr = self.execute_command("%s %s %s" % (svc_cmd, self.action, arguments), daemonize=True) else: - # SysV or systemd - rc_state, stdout, stderr = self.execute_command("%s %s %s" % (self.action, self.name, self.arguments), daemonize=True) + # SysV + rc_state, stdout, stderr = self.execute_command("%s %s %s" % (self.action, self.name, arguments), daemonize=True) else: # not all services support restart. Do it the hard way. if svc_cmd != '': - # upstart - rc1, stdout1, stderr1 = self.execute_command("%s %s %s" % (svc_cmd, 'stop', self.arguments), daemonize=True) + # upstart or systemd + rc1, stdout1, stderr1 = self.execute_command("%s %s %s" % (svc_cmd, 'stop', arguments), daemonize=True) else: - # SysV or systemd - rc1, stdout1, stderr1 = self.execute_command("%s %s %s" % ('stop', self.name, self.arguments), daemonize=True) + # SysV + rc1, stdout1, stderr1 = self.execute_command("%s %s %s" % ('stop', self.name, arguments), daemonize=True) if svc_cmd != '': - # upstart - rc2, stdout2, stderr2 = self.execute_command("%s %s %s" % (svc_cmd, 'start', self.arguments), daemonize=True) + # upstart or systemd + rc2, stdout2, stderr2 = self.execute_command("%s %s %s" % (svc_cmd, 'start', arguments), daemonize=True) else: - # SysV or systemd - rc2, stdout2, stderr2 = self.execute_command("%s %s %s" % ('start', self.name, self.arguments), daemonize=True) + # SysV + rc2, stdout2, stderr2 = self.execute_command("%s %s %s" % ('start', self.name, arguments), daemonize=True) # merge return information if rc1 != 0 and rc2 == 0: