TigerVNC 服务器无法在 systemctl 内工作但单独工作正常

TigerVNC 服务器无法在 systemctl 内工作但单独工作正常

我已经在 Ubuntu 22.04LTS 上设置了 TigerVNC 服务器。我创建了一个文件,以使服务在启动时启动,使用以下配置:/etc/systemd/system/[email protected]

[Unit]
Description=Start TigerVNC server at startup
After=syslog.target network.target

[Service]
Type=simple
User=monitor
Group=monitor
WorkingDirectory=/home/monitor

PIDFile=/home/monitor/.vnc/%H:%i.pid
ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -verbose -depth 24 -geometry 1280x800 -localhost :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

在命令行中手动运行启动命令/usr/bin/vncserver -verbose -depth 24 -geometry 1280x800 -localhost可以正常工作,并且我可以使用远程 SSH 隧道 VNC 连接成功连接。没有显示任何错误消息或警告。

但是,使用sudo systemctl start vncserver@1不起作用。journalctl显示以下日志输出:

Apr 23 14:23:35 cucumber systemd[1]: Starting Start TigerVNC server at startup...
Apr 23 14:23:35 cucumber vncserver[5446]: vncserver: Option 2>&1: Unrecognized!
Apr 23 14:23:35 cucumber vncserver[5446]: vncserver usage:

... vncserver outputs its entire --help output here

Apr 23 14:23:35 cucumber systemd[1]: Started Start TigerVNC server at startup.
Apr 23 14:23:35 cucumber vncserver[5455]: Starting /usr/bin/Xtigervnc :1 -localhost=1 -desktop cucumber:1 (monitor) -rfbport 5901 -PasswordFile /home/mon>
Apr 23 14:23:35 cucumber vncserver[5455]: New Xtigervnc server 'cucumber:1 (monitor)' on port 5901 for display :1.
Apr 23 14:23:35 cucumber vncserver[5455]: Use xtigervncviewer -SecurityTypes VncAuth -passwd /home/monitor/.vnc/passwd :1 to connect to the VNC server.
Apr 23 14:23:35 cucumber vncserver[5455]: Starting session via '/home/monitor/.vnc/xstartup'
Apr 23 14:23:35 cucumber vncserver[5455]: Log file is /home/monitor/.vnc/cucumber:5901.log

... a couple of 'activating service'/'successfully activated' statements here

Apr 23 14:23:38 cucumber org.a11y.Bus[5489]: X connection to :1 broken (explicit kill or server shutdown).
Apr 23 14:23:38 cucumber org.gtk.vfs.Daemon[5509]: A connection to the bus can't be made
Apr 23 14:23:38 cucumber xfconfd[5483]: Name org.xfce.Xfconf lost on the message dbus, exiting.
Apr 23 14:23:38 cucumber tumblerd[5569]: Name org.freedesktop.thumbnails.Cache1 lost on the message dbus, exiting.
Apr 23 14:23:38 cucumber tumblerd[5569]: Name org.freedesktop.thumbnails.Manager1 lost on the message dbus, exiting.
Apr 23 14:23:38 cucumber tumblerd[5569]: Name org.freedesktop.thumbnails.Thumbnailer1 lost on the message dbus, exiting.
Apr 23 14:23:38 cucumber org.gtk.vfs.Daemon[5744]: A connection to the bus can't be made
Apr 23 14:23:38 cucumber vncserver[5779]: Killing Xtigervnc process ID 5456... success!
Apr 23 14:23:38 cucumber systemd[1]: [email protected]: Deactivated successfully.
Apr 23 14:23:38 cucumber systemd[1]: [email protected]: Consumed 2.477s CPU time.

以下是输出/home/monitor/.vnc/cucumber:5901.log

Xvnc TigerVNC 1.12.0 - built 2022-03-25 17:06
Copyright (C) 1999-2021 TigerVNC Team and many others (see README.rst)
See https://www.tigervnc.org for information on TigerVNC.
Underlying X server release 12101003, X.Org


Sat Apr 23 15:01:09 2022
 vncext:      VNC extension running!
 vncext:      Listening for VNC connections on local interface(s), port 5901
 vncext:      created VNC server for screen 0
[mi] mieq: warning: overriding existing handler (nil) with 0x562410d9e400 for event 2
[mi] mieq: warning: overriding existing handler (nil) with 0x562410d9e400 for event 3
3NI3X0 New Xtigervnc server 'cucumber:1 (monitor)' on port 5901 for display :1.
3NI3X0 Use xtigervncviewer -SecurityTypes VncAuth -passwd /home/monitor/.vnc/passwd :1 to connect to the VNC server.
/usr/bin/startxfce4: X server already running on display :1
gpg-agent: a gpg-agent is already running - not starting a new one

(xfwm4:9407): xfwm4-WARNING **: 15:01:10.009: Unsupported GL renderer (llvmpipe (LLVM 13.0.1, 256 bits)).

(wrapper-2.0:9449): GLib-GIO-CRITICAL **: 15:01:10.358: g_file_new_for_path: assertion 'path != NULL' failed

(wrapper-2.0:9449): GLib-GIO-CRITICAL **: 15:01:10.358: g_file_monitor_file: assertion 'G_IS_FILE (file)' failed

(wrapper-2.0:9449): GLib-GObject-WARNING **: 15:01:10.358: invalid (NULL) pointer instance

(wrapper-2.0:9449): GLib-GObject-CRITICAL **: 15:01:10.358: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed

(wrapper-2.0:9449): Gtk-WARNING **: 15:01:10.358: Attempting to add a widget with type GtkToggleButton to a container of type XfcePanelPlugin, but the widget is already inside a container of type XfcePanelPlugin, please remove the widget from its existing container first.

** (wrapper-2.0:9448): WARNING **: 15:01:10.365: No outputs have backlight property

(wrapper-2.0:9454): Gtk-WARNING **: 15:01:10.367: Negative content width -1 (allocation 1, extents 1x1) while allocating gadget (node button, owner XfceArrowButton)

(wrapper-2.0:9449): Gtk-WARNING **: 15:01:10.369: Negative content width -3 (allocation 1, extents 2x2) while allocating gadget (node button, owner GtkToggleButton)

(wrapper-2.0:9448): Gtk-CRITICAL **: 15:01:10.385: gtk_icon_theme_has_icon: assertion 'icon_name != NULL' failed

(wrapper-2.0:9448): Gtk-CRITICAL **: 15:01:10.386: gtk_icon_theme_has_icon: assertion 'icon_name != NULL' failed

(wrapper-2.0:9448): Gtk-CRITICAL **: 15:01:10.386: gtk_icon_theme_has_icon: assertion 'icon_name != NULL' failed

(wrapper-2.0:9448): Gtk-CRITICAL **: 15:01:10.387: gtk_icon_theme_has_icon: assertion 'icon_name != NULL' failed

(wrapper-2.0:9448): Gtk-WARNING **: 15:01:10.394: Negative content width -3 (allocation 1, extents 2x2) while allocating gadget (node button, owner PowerManagerButton)

** (xfce4-power-manager:9485): WARNING **: 15:01:10.407: Failed to get name owner: GDBus.Error:org.freedesktop.DBus.Error.NameHasNoOwner: Could not get owner of name 'org.xfce.PowerManager': no such name


** (xfce4-power-manager:9485): WARNING **: 15:01:10.407: Failed to get name owner: GDBus.Error:org.freedesktop.DBus.Error.NameHasNoOwner: Could not get owner of name 'org.freedesktop.PowerManagement': no such name

Xfce power manager is not running
Xlib:  extension "DPMS" missing on display ":1".

(xfce4-power-manager:9485): xfce4-power-manager-WARNING **: 15:01:10.411: Monitor is not DPMS capable

(wrapper-2.0:9447): Gtk-WARNING **: 15:01:10.414: Negative content width -3 (allocation 1, extents 2x2) while allocating gadget (node button, owner PulseaudioButton)
Xfce Power Manager: Another power manager is already running

** (xiccd:9505): WARNING **: 15:01:10.448: EDID is empty
Connection failure: Connection refused
pa_context_connect() failed: Connection refused

(xfce4-power-manager:9485): GLib-GObject-WARNING **: 15:01:10.454: ../../../gobject/gsignal.c:2613: signal 'Changed' is invalid for instance '0x55897a97d0c0' of type 'GDBusProxy'

** (xiccd:9505): CRITICAL **: 15:01:10.459: failed to create colord device: failed to obtain org.freedesktop.color-manager.create-device auth

(xfce4-power-manager:9485): xfce4-power-manager-WARNING **: 15:01:10.470: could not map keysym 1008ffa8 to keycode

Another notification daemon is running, exiting

(xfce4-power-manager:9485): xfce4-power-manager-WARNING **: 15:01:10.476: Unable to inhibit systemd sleep: GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: Permission denied

** (xfce4-power-manager:9485): WARNING **: 15:01:10.476: No outputs have backlight property

(xfce4-power-manager:9485): xfce4-power-manager-WARNING **: 15:01:10.490: Failed to get keyboard max brightness level : GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: Object does not exist at path “/org/freedesktop/UPower/KbdBacklight”

** (light-locker:9537): ERROR **: 15:01:10.514: session_id is not set, is /proc mounted with hidepid>0?

** (xiccd:9505): WARNING **: 15:01:12.848: Exiting

(xfsettingsd:9431): libxfce4ui-WARNING **: 15:01:12.849: ICE I/O Error

(xfsettingsd:9431): libxfce4ui-WARNING **: 15:01:12.849: Disconnected from session manager.

(Thunar:9438): thunar-WARNING **: 15:01:12.851: Name 'org.xfce.FileManager' lost on the message dbus.

(Thunar:9438): thunar-WARNING **: 15:01:12.851: Name 'org.freedesktop.FileManager1' lost on the message dbus.
xfsettingsd: Another instance took over. Leaving...

(xfce4-power-manager:9485): libxfce4ui-WARNING **: 15:01:12.850: ICE I/O Error

(xfce4-power-manager:9485): libxfce4ui-WARNING **: 15:01:12.854: Disconnected from session manager.

** (xfce4-power-manager:9485): WARNING **: 15:01:12.856: Error: The connection is closed


** (xfce4-power-manager:9485): WARNING **: 15:01:12.856: Error: The connection is closed

The X session cleanly exited!
Killing Xtigervnc process ID 9358...XIO:  fatal IO error 25 (Inappropriate ioctl for device) on X server ":1.0"
      after 20 requests (20 known processed) with 0 events remaining.

Sat Apr 23 15:01:12 2022
 ComparingUpdateTracker: 0 pixels in / 0 pixels out
 ComparingUpdateTracker: (1:-nan ratio)

(x-window-manager:9685): Gtk-WARNING **: 15:01:12.872: cannot open display: :1
 success!

答案1

是的,至少有两个在线教程(12) 在 Ubuntu 20.04 上通过 systemd 运行 TigerVNC 的功能在 Ubuntu 22.04 上不再起作用,部分原因是这个问题。

ExecStartPre尝试将systemd 单元文件中的行更改为以下内容:

ExecStartPre=-/usr/bin/vncserver -kill :%i

然后执行systemctl daemon-reloadsystemctl start vncserver@1

为什么?

  • Ubuntu 22.04 似乎现在将输出重定向 ( 2>&1)vncserver作为参数传递给命令(而不是将其解释为 shell)。重定向似乎不是必需的。
  • 减号 ( -) 可防止此命令的任何非零退出代码导致服务失败(参考,请参阅“表 1. 特殊可执行前缀”)。我不确定是否需要它,但它不会造成伤害,DigitalOcean 教程可以。

注意,我还必须安装dbus-x11包,因为我的/etc/vnc/xstartup文件使用了该dbus-launch命令。

相关内容