I have created a simple Qt console application (dbus service) and I need to launch it using systemd.
However every time I execute systemctl start my_serv it fails to start the application and I end up having log in journalctl -xe indicating that application has failed to load libQt5Gui.so.5 (i'm pretty sure it is not related to this particular library):
raspberrypi systemd[1]: Started my_serv.service.
raspberrypi MyService[2812]: /opt/services/MyService: error while loading shared libraries: libQt5Gui.so.5: cannot open shared object file: No such file or directory
raspberrypi systemd[1]: my_serv.service: main process exited, code=exited, status=127/n/a
raspberrypi systemd[1]: Unit my_serv.service entered failed state.
From the other hand application launches fine when I do this from console under root user (i.e. it fails to register an object on dbus, but I think it is not relevant):
./MyService
WELCOME FROM MY SERVICE
Object was registered on dbus
Service was not registered on dbus
Qt libraries are locates by the following path:
ls -al /usr/local/qt5/lib/libQt5Gui.*
-rwxrwxrwx /usr/local/qt5/lib/libQt5Gui.la
-rwxrwxrwx /usr/local/qt5/lib/libQt5Gui.prl
lrwxrwxrwx /usr/local/qt5/lib/libQt5Gui.so -> libQt5Gui.so.5.9.1
lrwxrwxrwx /usr/local/qt5/lib/libQt5Gui.so.5 -> libQt5Gui.so.5.9.1
lrwxrwxrwx /usr/local/qt5/lib/libQt5Gui.so.5.9 -> libQt5Gui.so.5.9.1
-rwxrwxrwx /usr/local/qt5/lib/libQt5Gui.so.5.9.1
It seems that everything is fine with links to libraries in the binary. The ldd output is as follows:
ldd MyService
libQt5Gui.so.5 => /usr/local/qt5/lib/libQt5Gui.so.5 (0x76a92000)
libQt5DBus.so.5 => /usr/local/qt5/lib/libQt5DBus.so.5 (0x76a0d000)
libQt5Core.so.5 => /usr/local/qt5/lib/libQt5Core.so.5 (0x7654e000)
The service file looks like this (/etc/systemd/system/my_serv.service)
[Service]
ExecStart=/opt/services/MyService
User=root
Most probably the linker directories are not known in the context of systemctl
. Try setting the environment variable LD_LIBRARY_PATH
to the relevant dirs at the start of your service script; see man ld.so
for details. Or look at other service scripts on your system to get an idea how the environment is correctly set there.