Run chkconfig enable/disable only when needed. TODO, apply same logic to update-rc.d/systemd

pull/2193/head
Michael DeHaan 12 years ago
parent 0380ba7177
commit 4be3b06842

@ -444,6 +444,19 @@ class LinuxService(Service):
if self.enable_cmd is None: if self.enable_cmd is None:
self.module.fail_json(msg='unable to find enable binary') self.module.fail_json(msg='unable to find enable binary')
# FIXME: we use chkconfig to decide whether to run the command here, but if we don't
# have chkconfig we need similar code for updates-rc.d and systemd.
if self.enable_cmd.endswith("chkconfig"):
(rc, out, err) = self.execute_command("%s --list %s" % (self.enable_cmd, self.name))
if not self.name in out:
self.module.exit_json(msg="unknown service name")
state = out.split()[-1]
if self.enable and ( "3:on" in out and "5:on" in out ):
return
elif not self.enable and ( "3:off" in out and "5:off" in out ):
return
# we change argument depending on real binary used # we change argument depending on real binary used
# update-rc.d wants enable/disable while # update-rc.d wants enable/disable while
# chkconfig wants on/off # chkconfig wants on/off
@ -462,15 +475,11 @@ class LinuxService(Service):
else: else:
args = (self.enable_cmd, self.name, on_off) args = (self.enable_cmd, self.name, on_off)
# FIXME: we need this function to detect whether to run the command self.changed = True
# so we need something to get the service enablement state here.
changed = True
if self.module.check_mode and changed: if self.module.check_mode and changed:
self.module.exit_json(changed=True, msg="editing service enablement") self.module.exit_json(changed=True)
if self.enable is not None and changed:
return self.execute_command("%s %s %s" % args) return self.execute_command("%s %s %s" % args)

Loading…
Cancel
Save