不使用 systemd 也可以运行。
配置如下:
ubuntu@yocto:~/.vnc$ cat xstartup
#!/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 &
我是这样开始的:
ubuntu@yocto:~$ vncserver -geometry 1920x1200 -depth 24
New 'yocto.c.annotator-1286.internal:1 (ubuntu)' desktop at :1 on machine yocto.c.annotator-1286.internal
Starting applications specified in /home/ubuntu/.vnc/xstartup
Log file is /home/ubuntu/.vnc/yocto.c.annotator-1286.internal:1.log
Use xtigervncviewer -SecurityTypes VncAuth -passwd /home/ubuntu/.vnc/passwd :1 to connect to the VNC server.
它像这样正确运行:
ubuntu@yocto:~$ vncserver -list
TigerVNC server sessions:
X DISPLAY # RFB PORT # PROCESS ID
:1 5901 1624
ubuntu@yocto:~$
我在 macOS 上创建了一个 ssh 隧道,如下所示:
gcloud compute --project "annotator-1286" ssh --zone "us-central1-a" "ubuntu@yocto" -- -NL 5901:localhost:5901
然后我可以通过指向localhost:5901来连接“Screen Sharing.app”。
但是,如果我不手动启动该服务,而是尝试将其作为 systemd 服务运行,则这些说明:
ubuntu@yocto:~$ cat .local/share/systemd/user/[email protected]
[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
启用并启动:
ubuntu@yocto:~$ systemctl daemon-reload --user
ubuntu@yocto:~$ systemctl enable vncserver@1 --user
Created symlink /home/ubuntu/.config/systemd/user/default.target.wants/[email protected] → /home/ubuntu/.local/share/systemd/user/[email protected].
ubuntu@yocto:~$ systemctl start vncserver@1 --user
它似乎确实启动了 vnc 服务器:
ubuntu@yocto:~$ vncserver -list
TigerVNC server sessions:
X DISPLAY # RFB PORT # PROCESS ID
:1 5901 1287
ubuntu@yocto:~$
但是如果您尝试连接到此,屏幕将因以下错误而变为空白:
ubuntu@yocto:~$ systemctl status vncserver@1 --user
● [email protected] - TigerVNC Service
Loaded: loaded (/home/ubuntu/.local/share/systemd/user/[email protected]; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-04-16 02:00:21 UTC; 3s ago
Process: 3493 ExecStartPre=/usr/bin/vncserver -kill :1 > /dev/null 2>&1 (code=exited, status=0/SUCCESS)
Process: 3499 ExecStart=/usr/bin/vncserver :1 -localhost no (code=exited, status=0/SUCCESS)
CGroup: /user.slice/user-1000.slice/[email protected]/vncserver.slice/[email protected]
├─3507 /usr/bin/Xtigervnc :1 -desktop yocto.c.annotator-1286.internal:1 (ubuntu) -auth /home/ubuntu/.Xauthority -geometry 1900x1200 -depth 24 -rfbwait 30000 -rfbau
├─3511 vncconfig -iconic
├─3515 dbus-launch --exit-with-session gnome-session
├─3516 /usr/bin/dbus-daemon --syslog --fork --print-pid 5 --print-address 7 --session
├─3521 /usr/lib/at-spi2-core/at-spi-bus-launcher
├─3526 /usr/bin/dbus-daemon --config-file=/usr/share/defaults/at-spi2/accessibility.conf --nofork --print-address 3
├─3530 /usr/lib/gvfs/gvfsd
├─3535 /usr/lib/gvfs/gvfsd-fuse /run/user/1000/gvfs -f -o big_writes
├─3545 /usr/bin/gnome-screensaver --no-daemon
├─3551 /usr/lib/at-spi2-core/at-spi2-registryd --use-gnome-session
└─3561 /usr/bin/gnome-keyring-daemon --start --components=secrets
Apr 16 02:00:22 yocto gnome-session[3512]: gnome-session-binary[3512]: WARNING: App 'org.gnome.Shell.desktop' exited with code 1
Apr 16 02:00:22 yocto gnome-session-binary[3512]: WARNING: App 'org.gnome.Shell.desktop' exited with code 1
Apr 16 02:00:22 yocto org.gnome.Shell.desktop[3572]: Window manager warning: Unsupported session type
Apr 16 02:00:22 yocto gnome-session[3512]: gnome-session-binary[3512]: WARNING: App 'org.gnome.Shell.desktop' exited with code 1
Apr 16 02:00:22 yocto gnome-session-binary[3512]: WARNING: App 'org.gnome.Shell.desktop' exited with code 1
Apr 16 02:00:22 yocto gnome-session[3512]: gnome-session-binary[3512]: WARNING: App 'org.gnome.Shell.desktop' respawning too quickly
Apr 16 02:00:22 yocto gnome-session-binary[3512]: WARNING: App 'org.gnome.Shell.desktop' respawning too quickly
Apr 16 02:00:22 yocto gnome-session-binary[3512]: Unrecoverable failure in required component org.gnome.Shell.desktop
Apr 16 02:00:22 yocto gnome-session[3512]: gnome-session-binary[3512]: CRITICAL: We failed, but the fail whale is dead. Sorry....
Apr 16 02:00:22 yocto gnome-session-binary[3512]: CRITICAL: We failed, but the fail whale is dead. Sorry....
ubuntu@yocto:~$
这些 gnome 错误非常常见,我很难调试这个问题。
我不太明白为什么只有在作为 systemd 服务运行时才会出现这些错误。
我确实必须像这样禁用 Wayland:
ubuntu@yocto:/etc/gdm3$ cat custom.conf
# GDM configuration storage
#
# See /usr/share/gdm/gdm.schemas for a list of available options.
[daemon]
# Uncomment the line below to force the login screen to use Xorg
WaylandEnable=false
# Enabling automatic login
# AutomaticLoginEnable = true
# AutomaticLogin = user1
# Enabling timed login
# TimedLoginEnable = true
# TimedLogin = user1
# TimedLoginDelay = 10
[security]
[xdmcp]
[chooser]
[debug]
# Uncomment the line below to turn on debugging
# More verbose logs
# Additionally lets the X server dump core if it crashes
#Enable=true
作为一个解决方法为了这:
ubuntu@yocto:~/.vnc$ systemctl status gdm
● gdm.service - GNOME Display Manager
Loaded: loaded (/lib/systemd/system/gdm.service; static; vendor preset: enabled)
Active: active (running) since Wed 2020-04-15 23:17:56 UTC; 26min ago
Main PID: 1125 (gdm3)
Tasks: 3 (limit: 4410)
Memory: 4.1M
CGroup: /system.slice/gdm.service
└─1125 /usr/sbin/gdm3
Apr 15 23:17:44 yocto systemd[1]: Starting GNOME Display Manager...
Apr 15 23:17:56 yocto systemd[1]: Started GNOME Display Manager.
Apr 15 23:17:56 yocto gdm-launch-environment][1130]: pam_unix(gdm-launch-environment:session): session opened for user gdm by (uid=0)
Apr 15 23:19:31 yocto gdm3[1125]: GdmDisplay: Session never registered, failing
Apr 15 23:19:31 yocto gdm3[1125]: Child process -1149 was already dead.
Apr 15 23:19:31 yocto gdm3[1125]: Child process -1149 was already dead.
Apr 15 23:19:31 yocto gdm-launch-environment][1917]: pam_unix(gdm-launch-environment:session): session opened for user gdm by (uid=0)
Apr 15 23:19:32 yocto gdm-launch-environment][1917]: pam_unix(gdm-launch-environment:session): session closed for user gdm
Apr 15 23:19:32 yocto gdm3[1125]: Child process -1944 was already dead.