Start a Qt/wayland application on top of weston on startup

init-scriptqtstartupsystemdwayland

I would like to launch a Qt application on start up. The application uses some of the features from weston/wayland desktop, so it should be launched on top of weston, right after weston is started. Normally, I work with SSH to connect to the target platform and launch the application using following commands:

systemctl stop weston
weston --tty=1
./QtApp

If I do not kill the weston and do not start it with a TTY, I get the following error:

Failed to create display

What I have tried to do is to set up a start up script and integrate it into the systemd:

[Unit]
Description = Onyx Service
After = weston.service
Type = forking

[Service]
ExecStart = /bin/bash /opt/onyx-start

[Install]
WantedBy = multi-user.target

However, as you can guess, this does not work. I need to manage to start an application on an existing weston instance that is not started with a TTY option.

Best Answer

Typically it's not about starting Weston on a specific tty, but about having the environment variables set which will route you to the proper instances of Wayland and Weston. These variables are such as WAYLAND_DISPLAY and even DISPLAY for applications that need XWayland.

You can typically get the proper environment you need by sourcing a file such as /etc/profile.d/weston.sh (or wayland_env.sh in some cases.) This is typically done for you when you log in to a shell, but systemd jobs do not launch a shell, so they don't get these variables set.

Maybe try something like this in onyx-start:

#!/bin/sh
. /etc/profile.d/weston.sh
exec /path/to/QtApp

The service unit you have should work with that.

(If it still doesn't work, please list more details about your environment, such as the Linux distribution you're using, contents of weston.service, output of systemctl status weston.service, contents of weston.sh or wayland_env.sh and wether starting QtApp works through SSH without launching a new Weston, perhaps after sourcing the environment profile file, if for any reason those variables aren't being set on those connections.)

Related Question