Ubuntu
在 Ubuntu 18.04 上配置 TigerVNC systemd 程序
我一直在嘗試讓 TigerVNC 在桌面 Ubuntu 18.04(GNOME 和所有)的全新安裝上工作。執行
vncserver :1 -localhost no
讓我可以很好地連接,但我的 systemd 服務似乎不起作用。系統啟動後的日誌:
Xvnc TigerVNC 1.7.0 - built Dec 5 2017 09:25:01 Copyright (C) 1999-2016 TigerVNC Team and many others (see README.txt) See http://www.tigervnc.org for information on TigerVNC. Underlying X server release 11905000, The X.Org Foundation Wed Jul 10 15:13:27 2019 vncext: VNC extension running! vncext: Listening for VNC connections on all interface(s), port 5901 vncext: created VNC server for screen 0 vncconfig: unable to open display ":1" ** (process:1184): WARNING **: 15:13:28.311: Could not make bus activated clients aware of XDG_CURRENT_DESKTOP=GNOME environment variable: Could not connect: Connection refused
在終端( )中手動啟動 vncserver 後登錄
vncserver :1 -localhost no
:Xvnc TigerVNC 1.7.0 - built Dec 5 2017 09:25:01 Copyright (C) 1999-2016 TigerVNC Team and many others (see README.txt) See http://www.tigervnc.org for information on TigerVNC. Underlying X server release 11905000, The X.Org Foundation Wed Jul 10 15:14:25 2019 vncext: VNC extension running! vncext: Listening for VNC connections on all interface(s), port 5901 vncext: created VNC server for screen 0 XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":1" after 175 requests (174 known processed) with 0 events remaining.
啟動:
#!/bin/sh [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources vncconfig -iconic & dbus-launch --exit-with-session gnome-session &
vncserver@.service
[Unit] Description=TigerVNC Service After=syslog.target network.target [Service] Type=simple User=<user> PAMName=login PIDFile=/home/<user>/.vnc/%H:%i.pid ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1 ExecStart=/usr/bin/vncserver :%i -localhost no ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=multi-user.target
經過反複試驗,我決定在使用者登錄後在使用者模式下執行該程序。使用者登錄後服務啟動,並啟用自動登錄,它可以很好地滿足我的目的。
我刪除了文件並使用以下內容
/etc/systemd/system/vncserver@.service
創建了一個新文件(並創建了失去的文件夾)。$HOME/.local/share/systemd/user/vncserver@.service
vncserver@.service
[Unit] Description=TigerVNC Service [Service] Type=forking ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1 ExecStart=/usr/bin/vncserver :%i -localhost no ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=default.target
然後我啟用了該服務
systemctl daemon-reload --user
並使用systemctl enable vncserver@1 --user
.