D-Bus: Difference between revisions
Prabuanand (talk | contribs) (added back a tip to check the service and changed introduction paragraph) |
Prabuanand (talk | contribs) (rephrased sentence and links that might cause ambiguity) |
||
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. | ||
== Installation == | == Installation == | ||
Install the dbus package: {{cmd|# apk add {{pkg|dbus}}}} | Install the dbus package: {{cmd|# apk add {{pkg|dbus}}}} | ||
Line 11: | Line 7: | ||
If you want dbus to be started at system startup enable the [[OpenRC]] service: {{cmd|# rc-update add dbus}} | If you want dbus to be started at system startup enable the [[OpenRC]] service: {{cmd|# rc-update add dbus}} | ||
To start the service immediately, use service '''start|stop|restart''' commands as follows: {{cmd|# rc-service dbus start}} | To start the service immediately, use service '''start|stop|restart''' commands as follows: {{cmd|# rc-service dbus start}} | ||
{{Tip|If system D-Bus is running, the command:{{ic|$ rc-service dbus status}} will output {{ic|* status: started}}.}} | |||
== D-Bus session == | == D-Bus session == | ||
{{ | System D-Bus service needs to be installed and running before launching a D-Bus session instance. You can start a {{ic|dbus session}} using the command like this: {{ic|dbus-run-session -- sh}}, by replacing '''sh''' with your shell or a window manager. | ||
If you are running a X11 based window manager using {{Path|.xinitrc}}, use : {{ic|exec dbus-launch --exit-with-session your_favourite_wm}} so that 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 without a <code>export $(dbus-launch)</code>. | |||
{{Tip| If D-Bus session bus is properly configured, the command:{{ic|$ echo $DBUS_SESSION_BUS_ADDRESS}} must provide a output.}} | |||
If <code>$DBUS_SESSION_BUS_ADDRESS</code> is undefined, many applications will attempt to use the standard path:{{ic|$XDG_RUNTIME_DIR/bus}} | If <code>$DBUS_SESSION_BUS_ADDRESS</code> is undefined, many applications will attempt to use the standard path:{{ic|$XDG_RUNTIME_DIR/bus}} | ||
Line 43: | Line 41: | ||
== See also == | == See also == | ||
* [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]] |
Revision as of 16:10, 31 May 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 you are using x11 you might also want to install the X11 add-ons which provide the dbus-launch
command:
# apk add dbus-x11
If you want dbus to be started at system startup enable the OpenRC service:
# rc-update add dbus
To start the service immediately, use service start|stop|restart commands as follows:
# rc-service dbus start
$ rc-service dbus status
will output * status: started
.D-Bus session
System D-Bus service needs to be installed and running before launching a D-Bus session instance. You can start a dbus session
using the command like this: dbus-run-session -- sh
, by replacing sh with your shell or a window manager.
If you are running a X11 based window manager using .xinitrc, use : exec dbus-launch --exit-with-session your_favourite_wm
so that D-Bus passes the environment variable $DBUS_SESSION_BUS_ADDRESS
to its children. Running dbus-launch
in a terminal means that other running process won't find this D-Bus's socket without a export $(dbus-launch)
.
$ echo $DBUS_SESSION_BUS_ADDRESS
must provide a 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