mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
#6341: use shared function for parsing systemd status; check rc code
This commit is contained in:
parent
d59973295d
commit
18f53d9219
1 changed files with 12 additions and 7 deletions
|
@ -473,18 +473,25 @@ class LinuxService(Service):
|
|||
if location.get('initctl', None):
|
||||
self.svc_initctl = location['initctl']
|
||||
|
||||
def get_systemd_status_dict(self):
|
||||
(rc, out, err) = self.execute_command("%s show %s" % (self.enable_cmd, self.__systemd_unit,))
|
||||
if rc != 0:
|
||||
self.module.fail_json('failure %d running systemctl show for %r: %s' % (self.__systemd_unit, rc, err))
|
||||
return dict(line.split('=', 1) for line in out.splitlines())
|
||||
|
||||
def get_systemd_service_status(self):
|
||||
(rc, out, err) = self.execute_command("%s show %s" % (self.enable_cmd, self.__systemd_unit))
|
||||
d = dict(line.split('=', 1) for line in out.splitlines())
|
||||
if d['ActiveState'] == 'active':
|
||||
d = self.get_systemd_status_dict()
|
||||
if d.get('ActiveState') == 'active':
|
||||
# run-once services (for which a single successful exit indicates
|
||||
# that they are running as designed) should not be restarted here.
|
||||
# Thus, we are not checking d['SubState'].
|
||||
self.running = True
|
||||
self.crashed = False
|
||||
elif d['ActiveState'] == 'failed':
|
||||
elif d.get('ActiveState') == 'failed':
|
||||
self.running = False
|
||||
self.crashed = True
|
||||
elif d.get('ActiveState') is None:
|
||||
self.module.fail_json(msg='No ActiveState value in systemctl show output for %r' % (self.__systemd_unit,))
|
||||
else:
|
||||
self.running = False
|
||||
self.crashed = False
|
||||
|
@ -605,9 +612,7 @@ class LinuxService(Service):
|
|||
return
|
||||
|
||||
if self.enable_cmd.endswith("systemctl"):
|
||||
(rc, out, err) = self.execute_command("%s show %s" % (self.enable_cmd, self.__systemd_unit))
|
||||
|
||||
d = dict(line.split('=', 1) for line in out.splitlines())
|
||||
d = self.get_systemd_status_dict()
|
||||
if "UnitFileState" in d:
|
||||
if self.enable and d["UnitFileState"] == "enabled":
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue