1

I've been trying to get TigerVNC working on a clean install of desktop Ubuntu 18.04 (GNOME and all). Running vncserver :1 -localhost no allows me to connect perfectly fine, but my systemd service does not seem to work.

Log after system boot:

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

Log after starting the vncserver manually in terminal (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.

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 &

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
0

After some trial and error, I decided to just run the process in user mode, after user has logged in. Service starts after user logs in, and with auto-login enabled it works perfectly fine for my purpose.

I removed /etc/systemd/system/vncserver@.service file and created a new one in $HOME/.local/share/systemd/user/vncserver@.service with the following contents (and created the missing folders).

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

Then I enabled the service with systemctl daemon-reload --user and enabled it with systemctl enable vncserver@1 --user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.