From 4cfda2a965f16180abeab2ac19510fe72f545567 Mon Sep 17 00:00:00 2001 From: Paul Sbarra Date: Thu, 21 Mar 2013 22:38:42 -0500 Subject: [PATCH 1/2] service: fix systemd compilation error with --check --- library/service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/service b/library/service index 14b231a2ef9..d0122c5de6a 100644 --- a/library/service +++ b/library/service @@ -499,7 +499,7 @@ class LinuxService(Service): self.changed = True - if self.module.check_mode and changed: + if self.module.check_mode and self.changed: self.module.exit_json(changed=True) return self.execute_command("%s %s %s" % args) From b545b4c5fcd708c65cb8c084290988b04f3ff794 Mon Sep 17 00:00:00 2001 From: Paul Sbarra Date: Sat, 23 Mar 2013 22:39:55 -0500 Subject: [PATCH 2/2] service: add systemd template support --- library/service | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/library/service b/library/service index d0122c5de6a..58d20d3cc53 100644 --- a/library/service +++ b/library/service @@ -369,10 +369,20 @@ class LinuxService(Service): elif location.get('systemctl', None): # verify service is managed by systemd - rc, out, err = self.execute_command("%s --all" % (location['systemctl'])) - look_for = "%s.service" % self.name - if look_for in out: - self.enable_cmd = location['systemctl'] + rc, out, err = self.execute_command("%s list-unit-files" % (location['systemctl'])) + + # adjust the service name to account for template service unit files + index = self.name.find('@') + if index == -1: + name = self.name + else: + name = self.name[:index+1] + + look_for = "%s.service" % name + for line in out.splitlines(): + if line.startswith(look_for): + self.enable_cmd = location['systemctl'] + break # Locate a tool for runtime service management (start, stop etc.) self.svc_cmd = '' @@ -473,10 +483,15 @@ class LinuxService(Service): return if self.enable_cmd.endswith("systemctl"): - (rc, out, err) = self.execute_command("%s is-enabled %s.service" % (self.enable_cmd, self.name)) - if self.enable and rc == 0: - return - elif not self.enable and rc == 1: + (rc, out, err) = self.execute_command("%s show %s.service" % (self.enable_cmd, self.name)) + + d = dict(line.split('=', 1) for line in out.splitlines()) + if "UnitFileState" in d: + if self.enable and d["UnitFileState"] == "enabled": + return + elif not self.enable and d["UnitFileState"] == "disabled": + return + elif not self.enable: return # we change argument depending on real binary used