@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:
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
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…)