mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] handle grabbing services status from alternate names, fix yunohost/issues#1134
This commit is contained in:
parent
911a4ec507
commit
d0b9eb1bdd
1 changed files with 47 additions and 19 deletions
|
@ -227,6 +227,27 @@ def service_status(names=[]):
|
||||||
|
|
||||||
status = _get_service_information_from_systemd(name)
|
status = _get_service_information_from_systemd(name)
|
||||||
|
|
||||||
|
# try to get status using alternative version if they exists
|
||||||
|
# this is for mariadb/mysql but is generic in case of
|
||||||
|
alternates = services[name].get("alternates", [])
|
||||||
|
while status is None and alternates:
|
||||||
|
status = _get_service_information_from_systemd(alternates.pop())
|
||||||
|
|
||||||
|
if status is None:
|
||||||
|
logger.error("Failed to get status information via dbus for service %s, systemctl didn't recognize this service ('NoSuchUnit')." % name)
|
||||||
|
result[name] = {
|
||||||
|
'status': "unknown",
|
||||||
|
'loaded': "unknown",
|
||||||
|
'active': "unknown",
|
||||||
|
'active_at': {
|
||||||
|
"timestamp": "unknown",
|
||||||
|
"human": "unknown",
|
||||||
|
},
|
||||||
|
'description': "Error: failed to get information for this service, it doesn't exists for systemd",
|
||||||
|
'service_file_path': "unknown",
|
||||||
|
}
|
||||||
|
|
||||||
|
else:
|
||||||
translation_key = "service_description_%s" % name
|
translation_key = "service_description_%s" % name
|
||||||
description = m18n.n(translation_key)
|
description = m18n.n(translation_key)
|
||||||
|
|
||||||
|
@ -256,13 +277,20 @@ def service_status(names=[]):
|
||||||
def _get_service_information_from_systemd(service):
|
def _get_service_information_from_systemd(service):
|
||||||
"this is the equivalent of 'systemctl status $service'"
|
"this is the equivalent of 'systemctl status $service'"
|
||||||
import dbus
|
import dbus
|
||||||
|
from dbus.exceptions import DBusException
|
||||||
|
|
||||||
d = dbus.SystemBus()
|
d = dbus.SystemBus()
|
||||||
|
|
||||||
systemd = d.get_object('org.freedesktop.systemd1','/org/freedesktop/systemd1')
|
systemd = d.get_object('org.freedesktop.systemd1','/org/freedesktop/systemd1')
|
||||||
manager = dbus.Interface(systemd, 'org.freedesktop.systemd1.Manager')
|
manager = dbus.Interface(systemd, 'org.freedesktop.systemd1.Manager')
|
||||||
|
|
||||||
|
try:
|
||||||
service_path = manager.GetUnit(service + ".service")
|
service_path = manager.GetUnit(service + ".service")
|
||||||
|
except DBusException as exception:
|
||||||
|
if exception.get_dbus_name() == 'org.freedesktop.systemd1.NoSuchUnit':
|
||||||
|
return None
|
||||||
|
raise
|
||||||
|
|
||||||
service_proxy = d.get_object('org.freedesktop.systemd1', service_path)
|
service_proxy = d.get_object('org.freedesktop.systemd1', service_path)
|
||||||
|
|
||||||
# unit_proxy = dbus.Interface(service_proxy, 'org.freedesktop.systemd1.Unit',)
|
# unit_proxy = dbus.Interface(service_proxy, 'org.freedesktop.systemd1.Unit',)
|
||||||
|
|
Loading…
Add table
Reference in a new issue