Fix for update-rc.d based systems that also have systemd installed
By default, the service module had assumed that if the system had the update-rc.d binary, the service was either managed via upstart or standard sysV init-style scripts. This patch adds a check for systemctl ahead of the other methods when update-rc.d is detected, and also simplifies the logic around the detection of systemctl-managed services
This commit is contained in:
parent
808d9596b2
commit
6c3af4df81
1 changed files with 31 additions and 23 deletions
|
@ -387,14 +387,36 @@ class LinuxService(Service):
|
||||||
for binary in binaries:
|
for binary in binaries:
|
||||||
location[binary] = self.module.get_bin_path(binary)
|
location[binary] = self.module.get_bin_path(binary)
|
||||||
|
|
||||||
|
def check_systemd(name):
|
||||||
|
# verify service is managed by systemd
|
||||||
|
if not location.get('systemctl', None):
|
||||||
|
return False
|
||||||
|
|
||||||
|
rc, out, err = self.execute_command("%s list-unit-files" % (location['systemctl']))
|
||||||
|
|
||||||
|
# adjust the service name to account for template service unit files
|
||||||
|
index = name.find('@')
|
||||||
|
if index != -1:
|
||||||
|
name = name[:index+1]
|
||||||
|
|
||||||
|
look_for = "%s.service" % name
|
||||||
|
for line in out.splitlines():
|
||||||
|
if line.startswith(look_for):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
# Locate a tool for enable options
|
# Locate a tool for enable options
|
||||||
if location.get('chkconfig', None) and os.path.exists("/etc/init.d/%s" % self.name):
|
if location.get('chkconfig', None) and os.path.exists("/etc/init.d/%s" % self.name):
|
||||||
# we are using a standard SysV service
|
# we are using a standard SysV service
|
||||||
self.enable_cmd = location['chkconfig']
|
self.enable_cmd = location['chkconfig']
|
||||||
elif location.get('update-rc.d', None) and os.path.exists("/etc/init/%s.conf" % self.name):
|
elif location.get('update-rc.d', None):
|
||||||
|
if check_systemd(self.name):
|
||||||
|
# service is managed by systemd
|
||||||
|
self.enable_cmd = location['systemctl']
|
||||||
|
elif os.path.exists("/etc/init/%s.conf" % self.name):
|
||||||
# service is managed by upstart
|
# service is managed by upstart
|
||||||
self.enable_cmd = location['update-rc.d']
|
self.enable_cmd = location['update-rc.d']
|
||||||
elif location.get('update-rc.d', None) and os.path.exists("/etc/init.d/%s" % self.name):
|
elif os.path.exists("/etc/init.d/%s" % self.name):
|
||||||
# service is managed by with SysV init scripts, but with update-rc.d
|
# service is managed by with SysV init scripts, but with update-rc.d
|
||||||
self.enable_cmd = location['update-rc.d']
|
self.enable_cmd = location['update-rc.d']
|
||||||
elif location.get('rc-service', None) and not location.get('systemctl', None):
|
elif location.get('rc-service', None) and not location.get('systemctl', None):
|
||||||
|
@ -402,23 +424,9 @@ class LinuxService(Service):
|
||||||
self.svc_cmd = location['rc-service']
|
self.svc_cmd = location['rc-service']
|
||||||
self.enable_cmd = location['rc-update']
|
self.enable_cmd = location['rc-update']
|
||||||
return
|
return
|
||||||
elif location.get('systemctl', None):
|
elif check_systemd(self.name):
|
||||||
|
# service is managed by systemd
|
||||||
# verify service is managed by systemd
|
|
||||||
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']
|
self.enable_cmd = location['systemctl']
|
||||||
break
|
|
||||||
|
|
||||||
# Locate a tool for runtime service management (start, stop etc.)
|
# Locate a tool for runtime service management (start, stop etc.)
|
||||||
if location.get('service', None) and os.path.exists("/etc/init.d/%s" % self.name):
|
if location.get('service', None) and os.path.exists("/etc/init.d/%s" % self.name):
|
||||||
|
|
Loading…
Reference in a new issue