From 3c40ce57007024111e44a6bcb899dc19ef19e766 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sun, 24 Feb 2013 11:58:05 -0500 Subject: [PATCH] Better detection of whether a service is managed by systemd or not. --- library/service | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library/service b/library/service index 0ddba3bb9b..a561b6cf6d 100644 --- a/library/service +++ b/library/service @@ -364,8 +364,12 @@ class LinuxService(Service): # service is managed by upstart self.enable_cmd = location['update-rc.d'] elif location.get('systemctl', None): - # service is managed by systemd - self.enable_cmd = location['systemctl'] + + # 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'] # Locate a tool for runtime service management (start, stop etc.) self.svc_cmd = '' @@ -447,7 +451,7 @@ class LinuxService(Service): def service_enable(self): if self.enable_cmd is None: - self.module.fail_json(msg='unable to find enable binary') + self.module.fail_json(msg='service name not recognized') # FIXME: we use chkconfig or systemctl # to decide whether to run the command here but need something