Starting and Stopping VNC with Fabric
We wanted to have a VNC server for client demos and for remote pairing on tasks. Our old VNC server was in the office, so the bandwidth available to anyone outside the office was pretty poor, leading to a pretty bad experience - lots of lag between doing anything and seeing the result, slow screen updates etc.
So we've now set up a server with Linode for running VNC sessions. To make it easy for clients to connect for demos we've setup two ways to connect to the VNC session through their web browser - a java applet, and the excellent guacamole servert (which uses the HTML 5 canvas element).
As the web connection is available, we don't want to leave a VNC server running all the time, as that might be a security risk. So we want our staff to start the VNC server when they need it, and stop it when they're finished. Of course they have other things on their minds, so we decided to write some scripts to make it easy for them to start and stop VNC.
The scripts need to be able to ssh into our VNC server, start the VNC server, then start the VNC client locally. When the VNC client exits the script should stop the VNC server. It would also be nice to be able to check what displays are available and give sensible options if the default display is already in use. Finally it would be good to be able to use an ssh tunnel - otherwise the traffic all goes in the clear.
We decided to use fabric - a python project that is all about setting up remote servers by running commands through ssh. And with a little code it can produce ssh tunnels.
We've posted a snapshot of our code on a github gist. (We've changed a few Aptivate specific values in it). You'll also need to get tunnels.py and generate your own copy of the vnc_passwd file with your own vnc password (see man vncpasswd for details of how to generate it). Lastly here is the README for how to use it.