From b2741f451e6d455a89f61d0248ffb32ea504e6fe Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Tue, 10 Sep 2013 22:19:15 -0500 Subject: [PATCH] Fixes to the service module for Ubuntu 12.04 (LTS) Fixes #3615 Fixes #3572 --- library/system/service | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/library/system/service b/library/system/service index 9cab0c12a99..bf214bccd5f 100644 --- a/library/system/service +++ b/library/system/service @@ -576,6 +576,7 @@ class LinuxService(Service): action = 'enable' else: action = 'disable' + (rc, out, err) = self.execute_command("%s -n %s %s" \ % (self.enable_cmd, self.name, action)) self.changed = False @@ -583,6 +584,12 @@ class LinuxService(Service): if line.startswith('rename'): self.changed = True break + elif self.enable and line.find('do not exist') != -1: + self.changed = True + break + elif not self.enable and line.find('already exist') != -1: + self.changed = True + break if self.module.check_mode: self.module.exit_json(changed=self.changed) @@ -590,7 +597,17 @@ class LinuxService(Service): if not self.changed: return - return self.execute_command("%s %s %s" % (self.enable_cmd, self.name, action)) + if self.enable: + # make sure the init.d symlinks are created + # otherwise enable might not work + (rc, out, err) = self.execute_command("%s %s defaults" \ + % (self.enable_cmd, self.name)) + if rc != 0: + return (rc, out, err) + + return self.execute_command("%s %s enable" % (self.enable_cmd, self.name)) + else: + return self.execute_command("%s -f %s remove" % (self.enable_cmd, self.name)) # we change argument depending on real binary used: # - update-rc.d and systemctl wants enable/disable