Ubuntu – x11vnc on Ubuntu 16.04 Gnome with systemd

gnomesystemdUbuntuvnc

I am having troubles to start x11vnc service on Ubuntu server 16.04 Gnome.
It used to work just fine under 14.04. Not sure if related to x11vnc itself or the systemd.

Here is the systemd service file :

[Unit]
Description=Start x11vnc at startup.
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /etc/x11vnc.pass -rfbport 5900 -shared -o /var/log/x11vnc.log

[Install]
WantedBy=multi-user.target

The /etc/x11vnc.pass is present and has been generated using x11vnc -storepasswd /etc/x11vnc.passwd

After reboot, x11vnc is started, but no luck to connect to it with vnc, and the x11vnc.log files says :

03/05/2017 16:12:19 passing arg to libvncserver: -rfbauth
03/05/2017 16:12:19 passing arg to libvncserver: /etc/x11vnc.pass
03/05/2017 16:12:19 passing arg to libvncserver: -rfbport
03/05/2017 16:12:19 passing arg to libvncserver: 5900
03/05/2017 16:12:19 x11vnc version: 0.9.13 lastmod: 2011-08-10  pid: 30259
xauth:  unable to generate an authority file name
03/05/2017 16:12:19 -auth guess: failed for display='unset'
03/05/2017 16:12:19 -auth guess: since we are root, retrying with FD_XDM=1
03/05/2017 16:12:19 -auth guess: failed for display='unset'

To validate that x11vnc works fine, I simply manually run on the server :

x11vnc -rfbauth /etc/x11vnc.passwd

and with that I can successfully connect with vnc. But how can I start it automatically ?

Best Answer

It sounds like your Upstart script ran when a user logged in. It would then have access environment variables related to the login and be running as a user.

The systemd translation you have runs as root in the background, not in the context of a login session.

If you want this to start when a particular user logins, considering using the Ubuntu Unity autostart feature instead.

In my experience, systemd is not well-suited for starting user applications during a graphical login process.