D-Bus: Difference between revisions

From Alpine Linux
(add actual installation instructions)
m (added wikilink)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
[https://en.wikipedia.org/wiki/D-Bus D-Bus] is a message bus system that provides a mechanism for inter-process communication.
[https://en.wikipedia.org/wiki/D-Bus D-Bus] is a message bus system that provides a mechanism for inter-process communication.  


Some services rely on a D-Bus session instance or expect it by default (including [[PipeWire#D-Bus|Pipewire]]). Other processes will only be able to communicate with these services if d-bus is running.
== Installation ==
 
Install the dbus package: {{cmd|# apk add {{pkg|dbus}}}}
 
If [[Xorg]] is used, install the {{pkg|dbus-x11}} package which provides the {{ic|dbus-launch}} command needed for [[#D-Bus session bus|D-Bus session bus]] as follows:{{cmd|# apk add {{pkg|dbus-x11}}}}
 
== Configuration ==
 
=== System D-Bus ===
 
To start system D-Bus service {{ic|dbus}} at startup, enable it as follows: {{cmd|# rc-update add dbus}}


== Installation ==
To start the system D-Bus service immediately, use [[OpenRC]] service '''start|stop|restart''' commands as follows: {{cmd|# rc-service dbus start}}


Install the dbus package:
{{Tip|If System D-Bus is running, the command:{{ic|$ rc-service dbus status}} will output {{ic|* status: started}}.}}
{{cmd|# apk add {{pkg|dbus}}}}
If you are using x11 you might also want to install the X11 add-ons which provide the <code>dbus-launch</code> command:
{{cmd|# apk add {{pkg|dbus-x11}}}}
If you want dbus to be started at system startup enable the service:
{{cmd|# rc-update add dbus}}
To use the service without restarting you need to start it manually:
{{cmd|# rc-service dbus start}}
{{note|This only starts the system dbus. The dbus session is started separatly for each user.}}


== D-Bus session ==
=== D-Bus session bus===


You can start a dbus session like this: <code>dbus-run-session -- sh</code>(replacing sh with your shell or a window manager), or, <code>export $(dbus-launch)</code>.
{{Note|System D-Bus service needs to be running before launching an instance of D-Bus session bus.}}


D-Bus passes the environment variable <code>$DBUS_SESSION_BUS_ADDRESS</code> to its children. Running <code>dbus-launch</code> in a terminal means that other running process won't find this  D-Bus's socket.
To start a window manager along with D-bus session bus, use the command: {{ic|$ dbus-run-session -- <your_wm>}} by replacing '''<your_wm>''' with your shell or a window manager.


If <code>$DBUS_SESSION_BUS_ADDRESS</code> is undefined, many applications will attempt to use the standard path:
If X11 based window manager is started using {{Path|.xinitrc}}, to ensure that D-Bus session bus passes the environment variable <code>$DBUS_SESSION_BUS_ADDRESS</code>, add an entry as follows {{Cat|.xinitrc|exec dbus-launch --exit-with-session <your_wm>}}


$XDG_RUNTIME_DIR/bus
Running <code>dbus-launch</code> in a terminal requires {{ic|export $(dbus-launch)}}. If not, other running process won't find the socket of D-Bus session Bus.


Running D-Bus like so should work for many applications:
{{Tip|If D-Bus session bus is properly configured, the command:{{ic|$ echo $DBUS_SESSION_BUS_ADDRESS}} must provide an output.}}


{{Cmd|dbus-daemon --nofork --address unix:path{{=}}$XDG_RUNTIME_DIR/bus --session}}
If <code>$DBUS_SESSION_BUS_ADDRESS</code> is undefined, many applications will attempt to use the standard path:{{ic|$XDG_RUNTIME_DIR/bus}}


Running D-Bus like so should work for many applications: {{Cmd|dbus-daemon --nofork --address unix:path{{=}}$XDG_RUNTIME_DIR/bus --session}}


For applications that dont work without <code>$DBUS_SESSION_BUS_ADDRESS</code> you can prepend your program with the follow workaround script which avoid launching multiple user dbus sessions:
For applications that dont work without <code>$DBUS_SESSION_BUS_ADDRESS</code> you can prepend your program with the follow workaround script which avoid launching multiple user dbus sessions:
Line 48: Line 51:


== See also ==
== See also ==
* [[PipeWire#D-Bus|Pipewire and D-Bus]]
 
* [https://wiki.archlinux.org/title/D-Bus Archwiki]
* [https://wiki.archlinux.org/title/D-Bus Archwiki]
* [https://wiki.gentoo.org/wiki/D-Bus Gentoo Wiki]
* [https://wiki.gentoo.org/wiki/D-Bus Gentoo Wiki]


[[Category:System Administration]]
[[Category:System Administration]]

Latest revision as of 07:01, 28 July 2025

D-Bus is a message bus system that provides a mechanism for inter-process communication.

Installation

Install the dbus package:

# apk add dbus

If Xorg is used, install the dbus-x11 package which provides the dbus-launch command needed for D-Bus session bus as follows:

# apk add dbus-x11

Configuration

System D-Bus

To start system D-Bus service dbus at startup, enable it as follows:

# rc-update add dbus

To start the system D-Bus service immediately, use OpenRC service start|stop|restart commands as follows:

# rc-service dbus start

Tip: If System D-Bus is running, the command:$ rc-service dbus status will output * status: started.

D-Bus session bus

Note: System D-Bus service needs to be running before launching an instance of D-Bus session bus.

To start a window manager along with D-bus session bus, use the command: $ dbus-run-session -- <your_wm> by replacing <your_wm> with your shell or a window manager.

If X11 based window manager is started using .xinitrc, to ensure that D-Bus session bus passes the environment variable $DBUS_SESSION_BUS_ADDRESS, add an entry as follows

Contents of .xinitrc

exec dbus-launch --exit-with-session <your_wm>

Running dbus-launch in a terminal requires export $(dbus-launch). If not, other running process won't find the socket of D-Bus session Bus.

Tip: If D-Bus session bus is properly configured, the command:$ echo $DBUS_SESSION_BUS_ADDRESS must provide an output.

If $DBUS_SESSION_BUS_ADDRESS is undefined, many applications will attempt to use the standard path:$XDG_RUNTIME_DIR/bus

Running D-Bus like so should work for many applications:

dbus-daemon --nofork --address unix:path=$XDG_RUNTIME_DIR/bus --session

For applications that dont work without $DBUS_SESSION_BUS_ADDRESS you can prepend your program with the follow workaround script which avoid launching multiple user dbus sessions:

#!/bin/sh
if [ ! -e "/tmp/dbus-$USER-env" ]; then
       echo "Creating new dbus session on /tmp/dbus-$USER-env"
       export $(dbus-launch)
       echo "${DBUS_SESSION_BUS_ADDRESS}" > /tmp/dbus-$USER-env
       echo "Dbus session address is: ${DBUS_SESSION_BUS_ADDRESS}"
else
       echo "Using dbus session address from /tmp/dbus-$USER-env"
       export DBUS_SESSION_BUS_ADDRESS="$(cat /tmp/dbus-$USER-env)"
       echo "Dbus session address is: ${DBUS_SESSION_BUS_ADDRESS}"
fi
if [ -n "$1" ]; then
       $@
fi

See also