Receiving systemd dbus signals
It demonstrates how to connect to systemd dbus signal. run this and stop/start crond using systemctl.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import dbus
import dbus.mainloop.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....'
print args
print kargs
properties_proxy = bus.get_object(
'org.freedesktop.systemd1',
interface.GetUnit('crond.service')
)
properties_interface = dbus.Interface(properties_proxy,
'org.freedesktop.DBus.Properties')
properties_interface.connect_to_signal('PropertiesChanged',
on_properties_changed)
import gobject
loop = gobject.MainLoop()
loop.run()