Starting up several dbus programs via systemd with a session bus

Simon McVittie smcv at collabora.com
Fri May 26 14:12:21 UTC 2017


On Fri, 26 May 2017 at 09:36:25 -0400, John Woltman wrote:
> I've been using dbus to develop a personal project for an embedded computer
> running Linux (Debian Jessie, which has systemd).  The project is made of four
> programs, all communicating over a dbus session bus.
...
> However, I cannot figure out how to make systemd service files that actually
> start all four programs up at boot time and share the same session bus.

The dbus 1.8.x version in Debian 8 'jessie' is too old to do this well.
Please use Debian 9 'stretch' (which is not yet a stable release, but is
currently in freeze), or rebuild stretch's dbus 1.10.x source package
for jessie. Either way, you will need to install the dbus-user-session
package.

With a suitable dbus version, you can set the SystemdService key in
each D-Bus .service file to point to a corresponding systemd .service
file, for example similar to the patch attached to
<https://bugzilla.gnome.org/show_bug.cgi?id=755638>.

Having done that, you will need to arrange for a `systemd --user`
instance to be started for an appropriate user on boot. This is really
a systemd question rather than a dbus question, but creating
/var/lib/systemd/linger/$username or running
"loginctl enable-linger $username", then symlinking your systemd units
into /etc/systemd/user/default.target.wants/, is one easy way to do this.

Depending what your embedded system does, you might find that it's more
appropriate to make your four programs communicate via the system bus
instead of the session bus. The session bus is intended for login sessions
and login-like sessions that are approximately equivalent to logging in
to getty/login, xdm, sshd or similar; the system bus is intended for
system-level services like Avahi. Without knowing what you're doing,
I don't know which is better.

It is possible to backport the relevant dbus changes to 1.8.x if you really
need to - the critical parts are just the .service and .socket files
from dbus-user-session, and arranging for DBUS_SESSION_BUS_ADDRESS
to be set to "unix:path=$XDG_RUNTIME_DIR/bus". However, there are some
subtleties involved in making it work seamlessly, so upgrading to 1.10.x
is probably quicker.

    S


More information about the dbus mailing list