Created
May 9, 2022 17:47
-
-
Save 89luca89/e6142aa2625d498515d0ccbd5f6cfaa9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import dbus | |
import dbus.mainloop.glib | |
from dbus.mainloop.glib import DBusGMainLoop | |
from gi.repository import GLib | |
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) | |
bus = dbus.SystemBus() | |
proxy = bus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1') | |
interface = dbus.Interface(proxy, 'org.freedesktop.systemd1.Manager') | |
interface.Subscribe() | |
def on_properties_changed(*args, **kargs): | |
print('Status Changed....') | |
if args: | |
try: | |
print(args[1][dbus.String("ActiveState")]) | |
print(args[1][dbus.String("SubState")]) | |
print(args[1][dbus.String("ExecMainStatus")]) | |
except KeyError: | |
pass | |
properties_proxy = bus.get_object( | |
'org.freedesktop.systemd1', interface.GetUnit('tester-unit.service') | |
) | |
properties_interface = dbus.Interface( | |
properties_proxy, 'org.freedesktop.DBus.Properties' | |
) | |
properties_interface.connect_to_signal( | |
'PropertiesChanged', on_properties_changed | |
) | |
DBusGMainLoop(set_as_default=True) | |
loop = GLib.MainLoop() | |
loop.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment