Score:0

TigerVNC as service in 22.04 headless Ubuntu server fails to start

tt flag

I have set up TigerVNC on a headless Ubuntu 22.04 server in the cloud, so headless.

Launching

vncserver

as my sudo user works fine and I can connect via an SSH tunnel (although I cannot launch browsers, which is a different issue).

These are the contents of my xstartup file:

#!/bin/sh

test x"$SHELL" = x"" && SHELL=/bin/bash
test x"$1"     = x"" && set -- default

vncconfig -iconic &
"$SHELL" -l << EOF
export XDG_SESSION_TYPE=x11
export GNOME_SHELL_SESSION_MODE=ubuntu
dbus-launch --exit-with-session gnome-session --session=ubuntu
EOF
vncserver -kill $DISPLAY

This is the content of /etc/systemd/system/vncserver@.service:

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

[Service]
Type=forking
User=user
#Group=user
#WorkingDirectory=/home/user
PAMName=login
PIDFile=/home/user/.vnc/%H:%i.pid
ExecStartPre=/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -fg -depth 24 -geometry 1920x1080 -localhost :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

When applying sudo service vncserver@1 start or sudo systemctl start vncserver@1

Syslog records the following:

Oct 16 12:03:25 server systemd[1]: Starting Start TigerVNC server at startup...
Oct 16 12:03:25 server systemd[1]: Started Session 25 of User user.
Oct 16 12:03:25 server vncserver[3049]: vncserver: Option 2>&1: Unrecognized!
Oct 16 12:03:25 server vncserver[3049]:   For further help, consult the vncserver(1) and Xtigervnc(1) manual pages.
Oct 16 12:03:25 server systemd[1]: vncserver@1.service: Control process exited, code=exited, status=1/FAILURE
Oct 16 12:03:25 server systemd[1]: vncserver@1.service: Failed with result 'exit-code'.
Oct 16 12:03:25 server systemd[1]: Failed to start Start TigerVNC server at startup.
Oct 16 12:03:25 server systemd[1]: session-25.scope: Deactivated successfully.

I suspect there has been a change in the way recent versions of the software work, but I would appreciate some insight on the matter.

David avatar
cn flag
If it is in the cloud then someone is hosting it? Have you asked them if what you are trying to do can be done in this situation?
Mac Technicon avatar
tt flag
@David this is a virtual machine sitting on a datacentre. It is unlikely that the error error **Option 2>&1: Unrecognized!** is related to hosting.
Score:0
ng flag

You are using a service file meant for Ubuntu 20.04, but it needs to be slightly different for Ubuntu 22.04.

This should work:

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

[Service]
Type=forking
User=user
#Group=user
#WorkingDirectory=/home/user
PAMName=login
PIDFile=/home/user/.vnc/%H:590%i.pid
ExecStartPre=-/bin/sh -c "/usr/bin/vncserver -kill :%i > /dev/null 2>&1"
ExecStart=/usr/bin/vncserver -fg -depth 24 -geometry 1920x1080 -localhost :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target

Take note of the changes to the PIDFile and ExecStartPre lines. Source

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.