我想在每次系统启动时运行DISPLAY=:0 xhost +
。(我知道xhost +
的安全含义。)
这个在本地执行的命令工作得很好:
username@hostname:`$ DISPLAY=:0 xhost +
access control disabled, clients can connect from any host
但是,当我想通过下面的systemd服务文件运行它时,它会失败,如下所示。
username@hostname:/etc/systemd/system$ cat set-xhost.service
[Unit]
Description=Set access control for X server
[Service]
Type=oneshot
Environment=DISPLAY=:0
ExecStart=/usr/bin/xhost +
[Install]
WantedBy=multi-user.target
username@hostname:~$ sudo systemctl start set-xhost.service
Job for set-xhost.service failed because the control process exited with error code. See "systemctl status set-xhost.service" and "journalctl -xe" for details.
username@hostname:~$ sudo journalctl -u set-xhost.service
Jun 09 12:09:28 hostname systemd[1]: Starting Set access control for X server...
Jun 09 12:09:28 hostname xhost[7067]: No protocol specified
Jun 09 12:09:28 hostname xhost[7067]: /usr/bin/xhost: unable to open display ":0"
Jun 09 12:09:28 hostname systemd[1]: set-xhost.service: Main process exited, code=exited, status=1/FAILURE
Jun 09 12:09:28 hostname systemd[1]: Failed to start Set access control for X server.
Jun 09 12:09:28 hostname systemd[1]: set-xhost.service: Unit entered failed state.
Jun 09 12:09:28 hostname systemd[1]: set-xhost.service: Failed with result 'exit-code'.
背后的原因是什么?据我所知,这应该管用。这说明我错过了这方面的一些重要知识。
发布于 2020-06-09 12:53:33
由于您没有指定任何依赖项(如After=
),systemd通常会在引导过程中尽快运行您的服务。
很有可能“尽快”在实际的X11服务器启动之前就结束了。只有当xhost
能够与正在运行的X11服务器联系时,它才能工作。
https://unix.stackexchange.com/questions/591792
复制相似问题