Skip to content

Instantly share code, notes, and snippets.

@Psycojoker
Created May 10, 2018 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Psycojoker/c2c0d096966ac11f548618c0dbd422b1 to your computer and use it in GitHub Desktop.
Save Psycojoker/c2c0d096966ac11f548618c0dbd422b1 to your computer and use it in GitHub Desktop.
get all properties from a service from systemd using dbus (like "systemctl status $service")
import sys
import dbus
service = sys.argv[1]
d = dbus.SystemBus()
systemd = d.get_object('org.freedesktop.systemd1','/org/freedesktop/systemd1')
manager = dbus.Interface(systemd, 'org.freedesktop.systemd1.Manager')
service_path = manager.GetUnit(service + ".service")
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')
all_properties = properties_interface.GetAll(unit_proxy.dbus_interface)
for k, v in all_properties.items():
print k, v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment