mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-09-07 13:41:03 -07:00
service: add systemd template support
This commit is contained in:
parent
4cfda2a965
commit
b545b4c5fc
1 changed files with 23 additions and 8 deletions
|
@ -369,10 +369,20 @@ class LinuxService(Service):
|
||||||
elif location.get('systemctl', None):
|
elif location.get('systemctl', None):
|
||||||
|
|
||||||
# verify service is managed by systemd
|
# verify service is managed by systemd
|
||||||
rc, out, err = self.execute_command("%s --all" % (location['systemctl']))
|
rc, out, err = self.execute_command("%s list-unit-files" % (location['systemctl']))
|
||||||
look_for = "%s.service" % self.name
|
|
||||||
if look_for in out:
|
# adjust the service name to account for template service unit files
|
||||||
self.enable_cmd = location['systemctl']
|
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.)
|
# Locate a tool for runtime service management (start, stop etc.)
|
||||||
self.svc_cmd = ''
|
self.svc_cmd = ''
|
||||||
|
@ -473,10 +483,15 @@ class LinuxService(Service):
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.enable_cmd.endswith("systemctl"):
|
if self.enable_cmd.endswith("systemctl"):
|
||||||
(rc, out, err) = self.execute_command("%s is-enabled %s.service" % (self.enable_cmd, self.name))
|
(rc, out, err) = self.execute_command("%s show %s.service" % (self.enable_cmd, self.name))
|
||||||
if self.enable and rc == 0:
|
|
||||||
return
|
d = dict(line.split('=', 1) for line in out.splitlines())
|
||||||
elif not self.enable and rc == 1:
|
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
|
return
|
||||||
|
|
||||||
# we change argument depending on real binary used
|
# we change argument depending on real binary used
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue