[systemd-devel] General question about dbus-activatable services

Jonathan de Boyne Pollard j.deboynepollard-newsgroups at ntlworld.com
Thu Feb 16 14:02:04 UTC 2017


Christian Rebischke:
> I would like to start ibus-daemon automatically on login in my user session.

The person who told you that this was unnecessary because ibus already has a way
to run the daemon via "bus activation" is wrong.  There are various good reasons
to avoid bus activation, especially if one has a proper service management
subsystem available.  You are actually a fair portion of the way there.  You are
missing a couple of things, though.  Your systemd service unit is wrong, and
your DBus service definition is incomplete.

The goal is to connect the DBus broker with service management.  The way that
this all hangs together (in the wider world outwith systemd and Linux, as well)
is that a service client tells the DBus broker to auto-start the DBus service,
the DBus broker tells the service manager to start the service process, and the
service is marked as "ready" when it has registered a specific name with the
broker.

* http://jdebp.eu./Softwares/nosh/avoid-dbus-bus-activation.html
* http://jdebp.eu./Softwares/nosh/guide/per-user-dbus-demand-start.html

To achieve this, you first need to correct your systemd service unit.  The type
should be "bus", not "forking".  This tells systemd that the service is "ready"
when it has registered a particular name.  You also need to tell systemd this
name.  Moreover, you need to tell the daemon program not to erroneously fork in
a vain attempt to "daemonize" itself.  Hence:

> [Service]
> Type=bus
> ExecStart=/usr/bin/ibus-daemon --xim
> BusName=org.freedesktop.IBus

You also need to tell the DBus broker not to attempt to directly run the daemon,
but rather to run it indirectly by telling the service manager to start it.
 Your ibus/bus/org.freedesktop.IBus.service.in needs to read:

> [D-BUS Service]
> Name=org.freedesktop.IBus
> Exec=@bindir@/ibus-daemon --replace --xim --panel disable
> SystemdService=ibus.service

The DBus broker, as long as it has been invoked in such a way that it "knows"
that there's a service manager there, talks to the service manager to activate
the service.  There's nothing stopping you from enabling and starting it
yourself in the normal way (using the --user option to systemctl, remember) if
you don't want to rely upon on-demand activation by DBus service clients.


More information about the systemd-devel mailing list