Posts: 9
Joined: Thu Feb 21, 2019 8:25 am

Crontab issue with DBus

Thu Jun 13, 2019 11:43 am


I'm trying to start my applications on reboot in crontab. My applications 'userInterface' and 'Application' communicate to eachother using DBus and will start on boot. Unfortunately the DBus communication doesn't work when starting the applications as a cronjob.

The crontab code I used:
@reboot sleep 10; export DISPLAY=:0 && /home/pi/userInterface
@reboot sleep 15; export DBUS_SESSION_BUS_ADDRESS='unix:abstract=/var/run/user/1000/bus' && /home/pi/Application

Still the DBus connection doesn't work. The processes do start and do connect to the DBus. When starting both applications using the terminal, the DBus communication works fine.

Any ideas how to setup the DBus communication properly using crontab?

Thanks in advance

Posts: 661
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: Crontab issue with DBus

Thu Jun 13, 2019 1:23 pm

The environment for things started with cron is quite different to the environment in your login shell.

Also, to start services, use systemd service files, or if you want to go old school, sysv init scripts.
Example #1 of the systemd.service docs should get you started.
If you need delays, they can be added there as well, but you should actually use proper service dependencies.
As for the dbus stuff, systemd.service can do dbus things for you, but i have never worked with dbus, so can't help you there.


Posts: 9
Joined: Thu Feb 21, 2019 8:25 am

Re: Crontab issue with DBus

Fri Jun 14, 2019 8:59 am

Thanks for your answer.

I've fixed the problem and the applications are working fine now. The problem was not caused by crontab.
The problem was caused by the definition of the session bus in the QT program.

The session bus was defined as
QDBusConnection sessionBus = QDBusConnection::sessionBus();
In QT and when starting the applications using terminal, the communication worked. When using cron to start the applications it didn't work. I guess the QT serialport library couldn't find the right session bus in cron.

I changed the sessionBus to:
QDBusConnection sessionBus = QDBusConnection::connectToBus(QString("unix:path=/run/user/1000/bus"), "test");
Everything works fine now. The applications seem to find the right sessionBus now, because it's pre-defined.

The crontab code I used:
@reboot sleep 6; /home/pi/Application
@reboot sleep 8; export DISPLAY=:0 && /home/pi/userInterface

Return to “Troubleshooting”