Dbus: Failed to connect to socket /host/run/dbus/system

I am trying to check if the time was NTP synchronized.
I connect via resin CLI and then go into one of my containers.

root@a6e385b:~# balena exec -it 4aba7fde2842 bin//bash
root@raspberrypi3-a6e385b:/# DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket \
>   dbus-send \
>   --system \
>   --print-reply \
>   --reply-timeout=2000 \
>   --type=method_call \
>   --dest=org.freedesktop.timedate1 \
>   /org/freedesktop/timedate1  \
>   org.freedesktop.DBus.Properties.GetAll \
>   string:"org.freedesktop.timedate1"
Failed to open connection to "system" message bus: Failed to connect to socket /host/run/dbus/system_bus_socket: No such file or directory

Any idea what went wrong?

Hi @zagatta-sonah!

If you’re using a multi-container setup, you have to specifically specify which container(s) will get access to the DBUS socket via labels in the docker-compose.yml file, see: https://docs.resin.io/learn/develop/multicontainer/#labels

Let us know if that helps!

1 Like

And if I’m running a single container?

Had the same response from Python so tried in bash but also getting:

RUN    apt-get update \
&& apt-get install -yq ccache wireless-tools dbus 
RUN export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
RUN DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket \
dbus-send \
  --system \
  --print-reply \
  --reply-timeout=2000 \
  --type=method_call \
  --dest=org.freedesktop.NetworkManager \
  /org/freedesktop/NetworkManager  \
  org.freedesktop.DBus.Properties.GetAll \
  string:"org.freedesktop.NetworkManager" 

Failed to open connection to "system" message bus: Failed to connect to socket /host/run/dbus/system_bus_socket: No such file or directory

You are using the dbus-send command inside the Dockerfile. Instead of invoking it during build time, you need to do that in runtime from your start.sh script.

Elaborate?

I’m really just trying to get the python dbus api working but can’t get beyond invoking
import dbus
bus = dbus.SystemBus()

Get the same error about no such file

Was just trying bash as a pre-test

Advice?

@r4space, I believe I understand @majorz 's answer, although I don’t have much experience with dbus. It’s about the difference between the Dockerfile “instructions” RUN, CMD or ENTRYPOINT. The RUN instruction executes something that should modify the filesystem as a step to produce a docker image. Each RUN command results in a “layer” for the final image, and this is what majorz referred to as “build time”. The CMD and ENTRYPOINT instructions, on the other hand, specify something to be executed when your app container is started, which majorz called “runtime”.
Quoting balena’s Dockerfile documentation page:

  • https://www.balena.io/docs/learn/develop/dockerfile/
  • CMD - This command will be run when the container starts up on your device, whereas RUN commands will be executed on our build servers. In a balena application, this is typically used to execute a start script or entrypoint for the users application. CMD should always be the last command in your Dockerfile. The only processes that will run inside the container are the CMD command and all processes that it spawns.
  • Init System - Whatever you define as CMD in your Dockerfile will be PID 1 of the process tree in your container. It also means that this PID 1 process needs to know how to properly process UNIX signals, reap orphan zombie processes and if it crashes, your whole container crashes, meaning you lose logs and debug info.

So instead of these two lines:

RUN export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
RUN ... dbus-send ...

Try placing the commands inside a shell script (could also be a Python script) (which majorz called “start.sh”) and running that script with the CMD instruction, something like:

COPY ./my_dbus_test.sh my_dbus_test.sh
CMD my_dbus_test.sh

Note that whatever you execute with CMD (like my_dbus_test.sh) should be a “long-lived” process if you are planning to upload it through balena’s platform (git push or balena push). If it’s a script that runs and quits straight away, then if I recall correctly the supervisor will keep restarting the container in an endless loop and you won’t be able to see / interact with it. (You can tell I’ve learned the hard way…) :slight_smile:

1 Like

Hey guys, I have the labels in the docker compose but Im still coming up with this error on electron.

electron: 1.7.13
node: 10

Im running the balena-electron-react package in a multi-container configuration. I have this in my compose file

    build: ./electron
    privileged: true
    restart: always
    network_mode: host
    depends_on:
    - wifi-connect
    - gateway
    ports:
      - "5858:5858"
      - "8080:8080"
    labels:
      io.balena.features.kernel-modules: '1'
      io.balena.features.firmware: '1'
      io.balena.features.dbus: '1'
      io.balena.features.supervisor-api: '1'
      io.balena.features.balena-api: '1'
      io.balena.update.strategy: hand-over

And the console reads this. 


X.Org X Server 1.20.4
21.08.19 18:43:53 (-0400)   X Protocol Version 11, Revision 0
21.08.19 18:43:53 (-0400)   Build Operating System: Linux 4.15.0-48-generic armv8l Raspbian
21.08.19 18:43:53 (-0400)   Current Operating System: Linux 8955240 4.14.98 #1 SMP Mon Jun 17 13:13:40 UTC 2019 armv7l
21.08.19 18:43:53 (-0400)   Kernel command line: 8250.nr_uarts=0 bcm2708_fb.fbwidth=1280 bcm2708_fb.fbheight=800 bcm2708_fb.fbdepth=16 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3f000000 vc_mem.mem_size=0x3f600000  dwc_otg.lpm_enable=0 console=null rootfstype=ext4 rootwait vt.global_cursor_default=0 root=PARTUUID=cf17c89d-03 rootwait
21.08.19 18:43:53 (-0400)   Build Date: 05 June 2019  12:49:54PM
21.08.19 18:43:53 (-0400)   xorg-server 2:1.20.4-1+rpt1 (https://www.debian.org/support) 
21.08.19 18:43:53 (-0400)   Current version of pixman: 0.36.0
21.08.19 18:43:53 (-0400)   	Before reporting problems, check http://wiki.x.org
21.08.19 18:43:53 (-0400)   	to make sure that you have the latest version.
21.08.19 18:43:53 (-0400)   Markers: (--) probed, (**) from config file, (==) default setting,
21.08.19 18:43:53 (-0400)   	(++) from command line, (!!) notice, (II) informational,
21.08.19 18:43:53 (-0400)   	(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
21.08.19 18:43:53 (-0400)   (==) Log file: "/var/log/Xorg.0.log", Time: Wed Aug 21 22:43:53 2019
21.08.19 18:43:53 (-0400)   (==) Using system config directory "/usr/share/X11/xorg.conf.d"
21.08.19 18:44:02 (-0400)   [44:0821/224402.593135:ERROR:bus.cc(422)] Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
21.08.19 18:44:02 (-0400)   [44:0821/224402.616763:WARNING:audio_manager.cc(293)] Multiple instances of AudioManager detected
21.08.19 18:44:02 (-0400)   [44:0821/224402.616905:WARNING:audio_manager.cc(254)] Multiple instances of AudioManager detected
21.08.19 18:44:02 (-0400)   [44:0821/224402.746103:ERROR:bus.cc(422)] Failed to connect to the bus: /usr/bin/dbus-launch terminated abnormally without any error message

Hello @mowi22 .
The error is Failed to connect to the bus: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
The bus address seems incorrect.
Do you have an ENV DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket line in your Dockerfile?

1 Like

Ah, thanks, no, I’ve just added that to the dockerfile, but I’m still getting
Failed to connect to the bus: /usr/bin/dbus-launch terminated abnormally without any error message

Can you please share your Dockerfile?

# Build stage
##
FROM balenalib/%%BALENA_MACHINE_NAME%%-node:10-build as build

EXPOSE 8080 5858

# Move to app dir
WORKDIR /usr/src/app

# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
  apt-utils \
  clang \
  libxcb-image0 \
  libxcb-util0 \
  xdg-utils \
  network-manager \
  libdbus-1-dev \
  libgtk2.0-dev \
  libnotify-dev \
  libgnome-keyring-dev \
  libgconf2-dev \
  libasound2-dev \
  libcap-dev \
  libcups2-dev \
  libxtst-dev \
  libxss1 \
  libnss3-dev \
  libsmbclient \
  libssh-4 \
  libexpat-dev 

# Move package.json to filesystem
COPY ./app/package.json .

# Install npm modules for the application
RUN    JOBS=MAX rm -rf node_modules && npm install --unsafe-perm --production && npm cache clean --force\
    && node_modules/.bin/electron-rebuild


###
# Runtime
##
FROM balenalib/%%BALENA_MACHINE_NAME%%-node:10-run

# Move to app dir
WORKDIR /usr/src/app

# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
  xserver-xorg-core \
  xserver-xorg-input-all \
  xserver-xorg-video-fbdev \
  xorg \
  libxcb-image0 \
  libxcb-util0 \
  python3-dbus \
  network-manager \
  xdg-utils \
  libdbus-1-3 \
  libgtk2.0 \
  libnotify4 \
  libgnome-keyring0 \
  libgconf-2-4 \
  libasound2 \
  libcap2 \
  libcups2 \
  libxtst6 \
  libxss1 \
  libnss3 \
  libsmbclient \
  libssh-4 \
  fbset \
  libexpat1 

RUN apt-get update

RUN echo "#!/bin/bash" > /etc/X11/xinit/xserverrc \
  && echo "" >> /etc/X11/xinit/xserverrc \
  && echo 'exec /usr/bin/X -s 0 dpms -nocursor -nolisten tcp "$@"' >> /etc/X11/xinit/xserverrc

# Move app to filesystem
COPY ./app ./

# Copy the modules from the build step
COPY --from=build /usr/src/app/node_modules ./node_modules

# Build react app
RUN JOBS=MAX npm run build

## uncomment if you want systemd
ENV INITSYSTEM on

ENV UDEV=1

ENV DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket


# Start app
CMD ["bash", "/usr/src/app/start.sh"]

You may need to install the dbus-x11 package.

2 Likes

That did it. Thanks!

Also got this error

$ DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket \
  dbus-send \
  --system \
  --print-reply \
  --reply-timeout=2000 \
  --type=method_call \
  --dest=org.freedesktop.timedate1 \
  /org/freedesktop/timedate1  \
  org.freedesktop.DBus.Properties.GetAll \
  string:"org.freedesktop.timedate1"
Failed to open connection to "system" message bus: Failed to connect to socket /host/run/dbus/system_bus_socket: No such file or directory

I am not using a multi-container setup, however by adding the io.balena.features.dbus label to my container I was able to get dbus-x11 and dbus to work inside my Ubuntu 18 container.

Adding here in case it helps someone else.