Starting QT app as a Systemd service
-
@vmetodiev said in Starting QT app as a Systemd service:
I agree! My goal is to make the GUI application start as a service with only the X server running beneath it, without LXDE or any other desktop environment.
I am just struggling how to achieve it no additional overhead...So you want to start you Qt QML/QWidget application with SystemD and X-Server.
Your error looks very similar to this ==> https://community.toradex.com/t/starting-qt-app-as-a-systemd-service/15954So I guess you have to change qtapp.service to setup
QT_QPA_PLATFORM
.
Something like this:[Unit] Description=QT Application After=xserver.service [Service] Type=simple Environment="QT_QPA_PLATFORM=wayland-egl" ExecStart=/opt/TestQtApp ExecStop=/bin/bash -c 'pkill TestQtApp' Restart=always IgnoreSIGPIPE=no [Install] Alias=qtapp.service
-
@vmetodiev said in Starting QT app as a Systemd service:
Jan 07 14:58:57 apalis-imx6 TestQtApp[607]: qt.qpa.screen: QXcbConnection: Could not connect to display
Jan 07 14:58:57 apalis-imx6 TestQtApp[607]: Could not connect to any X display.i think you are just missing the "DISPLAY=:0" env variable?
try it manually by calling
DISPLAY=:0 /opt/TestQtApp
-
@KroMignon
Your error looks very similar to this ==> https://community.toradex.com/t/starting-qt-app-as-a-systemd-service/15954
-> Absolutely :D It was posted by me in the Toradex forum, than I switched here...Environment="QT_QPA_PLATFORM=wayland-egl"
-> As far I understand, in this case the QT app will work with Wayland instead of the X server, correct?@raven-worx
Well, I added it as an enviroment and achived a certain progress.root@apalis-imx6:~# cat /lib/systemd/system/qtapp.service [Unit] Description=QT Application After=xserver.service [Service] Type=simple Environment="DISPLAY=:0" ExecStart=/opt/TestQtApp ExecStop=/bin/bash -c 'pkill TestQtApp' Restart=always IgnoreSIGPIPE=no [Install] Alias=qtapp.service
The service now starts when I manually invoke it by "systemctl start qtapp".
Nevertheless, it won't start automatically after reboot. The journal log is empty. Maybe the "After=xserver.service" is not quite correct? -
@vmetodiev
do you start the xserver service manually?
if not you are also missingRequire=xserver.service
so it is ensured that its running when your qt app gets startedalso to start it after reboot, you have to call
systemctl enable qtapp
-
Yes, the service is enabled. Well, I added "Requires=xserver.service", but still the qtapp.service would not start.
The xserver is fine upon reboot, visible inside "ps -auxf".
Invoking " systemctl start qtapp" start the Qt app...
-
Maybe this service example might help.
-
@vmetodiev said in Starting QT app as a Systemd service:
Invoking " systemctl start qtapp" start the Qt app...
I am far a way to be a systemd expert, so I may be wrong.
But I guess you have to addWantedBy=multi-user.target
in the[Install]
section to start the service automatically. -
@KroMignon said in Starting QT app as a Systemd service:
But I guess you have to add WantedBy=multi-user.target in the [Install] section to start the service automatically.
yep, thats true, good catch
-
@SGaist @KroMignon
Yes, your suggestions helped. Now it works perfectly. Thank you so much for your support!!!I am providing the service files below:
xserver.service
[Unit] Description=X Server Conflicts=getty@tty1.service plymouth-quit.service After=systemd-user-sessions.service getty@tty1.service plymouth-quit.service [Service] ExecStart=/usr/bin/X ExecStop=/usr/bin/killall -9 X Restart=always IgnoreSIGPIPE=no [Install] Alias=display-manager.service
qtapp.service
[Unit] Description=QT Application Requires=xserver.service After=xserver.service [Service] Type=simple Environment="DISPLAY=:0" ExecStart=/opt/TestQtApp ExecStop=/bin/bash -c 'pkill TestQtApp' Restart=always IgnoreSIGPIPE=no [Install] WantedBy=multi-user.target
-