Fixes to the service module for Ubuntu 12.04 (LTS)

Fixes #3615
Fixes #3572
reviewable/pr18780/r1
James Cammarata 11 years ago
parent 5e8918cb2c
commit 5fe192e5e7

@ -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

Loading…
Cancel
Save