Hi, > > I usually recommend to use Type=notify or if that is not possible, I > > think forking is better then simple for most cases. > > See the difference: > > # systemctl cat fail.service > # /etc/systemd/system/fail.service > [Unit] > Description=fail > > [Service] > Type=simple > ExecStart=/bin/false > > # systemctl start fail.service > > # echo $? > 0
Thank you very much for the explaination. I know understand my confusion between the Job result and Unit states. My test program becomes: -- #!/usr/bin/python3 from gi.repository import GLib import dbus import dbus.mainloop.glib def subscribe(): sysbus = dbus.SystemBus() systemd1 = sysbus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1') def get_unit_state(unit_name): unit = manager.GetUnit(unit_name) unit_if = sysbus.get_object('org.freedesktop.systemd1', unit) unit_props = dbus.Interface(unit_if, 'org.freedesktop.DBus.Properties') print('Unit %s: ActiveState=%s, SubState=%s' % (unit, unit_props.Get('org.freedesktop.systemd1.Unit', 'ActiveState'), unit_props.Get('org.freedesktop.systemd1.Unit', 'SubState'))) def systemd_event_cb(pid, jobid, unit, result): print('received event for unit %s with result %s' % (unit, result)) get_unit_state(unit) print('and some time later') GLib.timeout_add(1000, get_unit_state, unit) systemd1.connect_to_signal('JobRemoved', systemd_event_cb) manager = dbus.Interface(systemd1, 'org.freedesktop.systemd1.Manager') manager.Subscribe() GLib.timeout_add(100, subscribe) dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) loop = GLib.MainLoop() loop.run() -- Now the output is: -- received event for unit fail.service with result done Unit /org/freedesktop/systemd1/unit/fail_2eservice: ActiveState=failed, SubState=failed and some time later Unit /org/freedesktop/systemd1/unit/fail_2eservice: ActiveState=failed, SubState=failed received event for unit davmail.service with result done Unit /org/freedesktop/systemd1/unit/davmail_2eservice: ActiveState=active, SubState=running and some time later Unit /org/freedesktop/systemd1/unit/davmail_2eservice: ActiveState=failed, SubState=failed -- I can use Unit ActiveState to assess Unit failure but need to wait a bit for some services as the failed state is not immediate. Also I'll try to fix davmail following your advice. Thanks, Alex