启动时在 westton 上启动 Qt/wayland 应用程序

moz*_*ors 5 startup init-script wayland systemd qt

我想在启动时启动 Qt 应用程序。该应用程序使用了 weston/wayland 桌面的一些功能,因此它应该在 weston 启动后立即在 weston 上启动。通常,我使用 SSH 连接到目标平台并使用以下命令启动应用程序:

systemctl stop weston
weston --tty=1
./QtApp
Run Code Online (Sandbox Code Playgroud)

如果我不杀死韦斯顿,也不用 TTY 启动它,我会收到以下错误:

Failed to create display
Run Code Online (Sandbox Code Playgroud)

我试图做的是设置一个启动脚本并将其集成到 systemd 中:

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

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

[Install]
WantedBy = multi-user.target
Run Code Online (Sandbox Code Playgroud)

但是,正如您所猜测的,这行不通。我需要设法在未使用 TTY 选项启动的现有 Weston 实例上启动应用程序。

fil*_*den 5

通常,这不是在特定的 tty 上启动 Weston,而是设置环境变量,将您路由到 Wayland 和 Weston 的正确实例。WAYLAND_DISPLAY这些变量甚至适用DISPLAY于需要 XWayland 的应用程序。

您通常可以通过获取诸如/etc/profile.d/weston.sh(或wayland_env.sh在某些情况下)之类的文件来获得所需的正确环境。这通常是在您登录 shell 时为您完成的,但 systemd 作业不会启动 shell,因此它们不会设置这些变量。

也许尝试这样的事情onyx-start

#!/bin/sh
. /etc/profile.d/weston.sh
exec /path/to/QtApp
Run Code Online (Sandbox Code Playgroud)

您拥有的服务单位应该与此合作。

(如果仍然不起作用,请列出有关您的环境的更多详细信息,例如您正在使用的 Linux 发行版、 的内容weston.service、 的输出systemctl status weston.service、 或 的内容weston.sh以及wayland_env.sh是否通过 SSH 启动 QtApp 而不启动新的 Weston,也许获取环境配置文件后,如果由于任何原因未在这些连接上设置这些变量。)