VNC at graphical login for Ubuntu 12.10 or 12.04

It sounds trivial; create an upstart script to start on boot, but this had me googling for a little while.

I used x11vnc as the vnc server. The main issue was that x11vnc needed to bind to an Xauthority file. In order to get it running for graphical login, the Xauthority needed to be for the desktop manager (in this case, lightdm) . It took me a while to find the right location ( ⁄var ⁄run ⁄lightdm ⁄root ⁄); once I had found the answer, the script was easy. I created a file in the upstart init script directory,  ⁄etc⁄init ⁄x11vnc.conf

Lets take a look at what this does; lines 1 and 3 are self explanatory, line 5, ensures that the vnc server is started at the right time (not before lightdm), otherwise the Xauthority file will not exist. Line 6 stops the vnc server on shutdown or reboot.

Lines 8 and 9 ensure that the vnc server is restarted if it fails, but if it respawns x times in y seconds it stops (10 times in 5 seconds in this case). This makes sure it is available but if there is a more serious problem, it stops trying. Line 10 ensures that the process has the correct permissions.

Finally, line 12 starts the x11vnc server. The -forever flag makes sure the server does not exit when a user logs out. The -auth flag is the Xauthority file, which lightdm stores in  ⁄var⁄run⁄lightdm⁄root⁄, usually :0, which indicates the display number lightdm binds to. The -display flag binds to display 0, though it should match the display number used for the Xauthority file. The -rfbauth flag is optional, used only if x11vnc has been configured to use a password file.

Reboot the system, and there it is. Simple but effective.