use is-enabled to check systemd service status.

reviewable/pr18780/r1
Jon Hadfield 10 years ago
parent 600fc15b42
commit b20b29bd17

@ -478,6 +478,12 @@ class LinuxService(Service):
if location.get('initctl', False):
self.svc_initctl = location['initctl']
def get_systemd_service_enabled(self):
(rc, out, err) = self.execute_command("%s is-enabled %s" % (self.enable_cmd, self.__systemd_unit,))
if rc == 0:
return True
return False
def get_systemd_status_dict(self):
(rc, out, err) = self.execute_command("%s show %s" % (self.enable_cmd, self.__systemd_unit,))
if rc != 0:
@ -692,11 +698,10 @@ class LinuxService(Service):
action = 'disable'
# Check if we're already in the correct state
d = self.get_systemd_status_dict()
if "UnitFileState" in d:
if self.enable and d["UnitFileState"] == "enabled":
service_enabled = self.get_systemd_service_enabled()
if self.enable and service_enabled:
self.changed = False
elif not self.enable and d["UnitFileState"] == "disabled":
elif not self.enable and not service_enabled:
self.changed = False
elif not self.enable:
self.changed = False

Loading…
Cancel
Save