登录前(X 启动后)使用 systemd 运行 GUI 应用程序?

登录前(X 启动后)使用 systemd 运行 GUI 应用程序?

我正在尝试使用 systemd 在 Ubuntu 机器上运行 TightVNC 服务器。单元文件 (/etc/systemd/system/tiger.service) 如下所示:

[Unit]
Description=Tiger VNC server
After=display-manager.service

[Service]
Type=simple
Environment=XAUTHORITY=/home/myusername/.Xauthority
ExecStart=/usr/bin/sudo -H -u myusername bash -c '/usr/bin/x0vncserver -rfbport 5901 -PasswordFile path-to-passwd-file -PollingCycle 30 -AlwaysShared -display :0'

我无法连接到 VNC 服务器并systemctl status tiger.service返回:

Jun 01 03:12:49 ubuntu systemd[1]: Started Tiger VNC server.
Jun 01 03:12:49 ubuntu sudo[958]:     root : TTY=unknown ; PWD=/ ; USER=myusername ; COMMAND=/bin/bash -c /opt/rmm-agent/x0vncserver -rfbport 5901 -PasswordFile /opt/rmm-agent
Jun 01 03:12:49 ubuntu sudo[958]: pam_unix(sudo:session): session opened for user myusername by (uid=0)
Jun 01 03:12:49 ubuntu sudo[958]: /usr/bin/x0vncserver: unable to open display ":0"
Jun 01 03:12:49 ubuntu systemd[1]: tiger.service: Main process exited, code=exited, status=1/FAILURE
Jun 01 03:12:49 ubuntu systemd[1]: tiger.service: Unit entered failed state.
Jun 01 03:12:49 ubuntu systemd[1]: tiger.service: Failed with result 'exit-code'.

systemctl start tiger.service如果我从控制台启动它,一切运行正常,我可以连接到 VNC 服务器。

我尝试过Requires=代替After=graphical.target代替。在所有情况下,display-manager.service我得到的结果都一样。unable to open display ":0"

答案1

在您登录之前,您的用户目录中可能没有 XAuthority。以下是有关在哪里查找的信息在 x11vnc 文档站点。XAuthority 仅存在于 root 中,其目录随显示管理器和 Ubuntu 版本的不同而变化,但那里有一些很好的线索。

我目前正在尝试让该 vnc 服务器在 Kubuntu 16.04 中自动启动,我的授权文件位于:

/var/run/lightdm/root/:0

相关内容