mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Merge pull request #698 from YunoHost/fix-service-info-for-disabled-services
[fix] Fix the dbus interface to get info for services
This commit is contained in:
commit
99bd378b94
1 changed files with 12 additions and 13 deletions
|
@ -325,7 +325,7 @@ def service_status(names=[]):
|
||||||
|
|
||||||
result[name] = {
|
result[name] = {
|
||||||
'status': str(status.get("SubState", "unknown")),
|
'status': str(status.get("SubState", "unknown")),
|
||||||
'loaded': "enabled" if str(status.get("LoadState", "unknown")) == "loaded" else str(status.get("LoadState", "unknown")),
|
'loaded': str(status.get("UnitFileState", "unknown")),
|
||||||
'active': str(status.get("ActiveState", "unknown")),
|
'active': str(status.get("ActiveState", "unknown")),
|
||||||
'description': description,
|
'description': description,
|
||||||
'service_file_path': str(status.get("FragmentPath", "unknown")),
|
'service_file_path': str(status.get("FragmentPath", "unknown")),
|
||||||
|
@ -343,26 +343,25 @@ 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:
|
# c.f. https://zignar.net/2014/09/08/getting-started-with-dbus-python-systemd/
|
||||||
service_path = manager.GetUnit(service + ".service")
|
# Very interface, much intuitive, wow
|
||||||
except DBusException as exception:
|
service_unit = manager.LoadUnit(service + '.service')
|
||||||
if exception.get_dbus_name() == 'org.freedesktop.systemd1.NoSuchUnit':
|
service_proxy = d.get_object('org.freedesktop.systemd1', str(service_unit))
|
||||||
return None
|
|
||||||
raise
|
|
||||||
|
|
||||||
service_proxy = d.get_object('org.freedesktop.systemd1', service_path)
|
|
||||||
|
|
||||||
# unit_proxy = dbus.Interface(service_proxy, 'org.freedesktop.systemd1.Unit',)
|
|
||||||
properties_interface = dbus.Interface(service_proxy, 'org.freedesktop.DBus.Properties')
|
properties_interface = dbus.Interface(service_proxy, 'org.freedesktop.DBus.Properties')
|
||||||
|
|
||||||
return properties_interface.GetAll('org.freedesktop.systemd1.Unit')
|
properties = properties_interface.GetAll('org.freedesktop.systemd1.Unit')
|
||||||
|
|
||||||
|
if properties.get("LoadState", "not-found") == "not-found":
|
||||||
|
# Service doesn't really exist
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return properties
|
||||||
|
|
||||||
|
|
||||||
def service_log(name, number=50):
|
def service_log(name, number=50):
|
||||||
|
|
Loading…
Add table
Reference in a new issue