Running an X-app without an X-server

March 15th, 2011

Hmm, I suppose this sounds like a really daft thing to do - why would you want to run a graphics application on a system without a GUI? Here are a few use cases:

  1. you manage a remote Unix server hosted abroad and of course it is headless and has no use for a Graphics environment
  2. you do have a full-blown Desktop system which has a working Xserver but for some sessions - possibly spawned by a root process - there is no access to the Xserver; you can emulate this with the following sequence entered into an xterm:
    su -
    su - username
    
    i.e. su to root and then to another user - this final session will have lost access to the Xserver
  3. you need to run a graphic tool designed to be called from the command-line; it still needs a GUI environment because it requires access to GUI elements perhaps to generate a graphics file. Lazy programming? Maybe, but that does not fix your problem

In my particular case I needed to run a command that need a GTK environment to generate a graphic image; the command was launched from a Zope application which in turn had been launched as a root service and ultimately it was designed to be run as a facility on a webserver. So I was hit by all these issues.

Ordinarily it should be possible to address issue 2 with some trickery with xhost and Xauthority but even this seems to be non-trivial. I had already identified Xvfb-server as a long-term solution to the first problem and fortunately those good folks on the Interweb were able to point me at a complete solution which does not even require an X server to be running all the time. Instead a virtual server can be created on the fly and brought down when it is finished with. All achieved by the script

xvfb-run

Kudos to darvasan for getting this together and making it easily available. On my SuSE 11.3 system, the script failed to run complaining with

mktemp: too few X's in template `Xauthority'

which was resolved by editing the script as follows:

- AUTHFILE=$(mktemp -p "$XVFB_RUN_TMPDIR" Xauthority) 
+ AUTHFILE=$(mktemp -p "$XVFB_RUN_TMPDIR" Xauthority.XXXXXXXX)

Kudos for that one goes to olesen, an almost anonymous dude on Red Hat Bugzilla.

So having installed the Xvfb server you can now execute the following:

xvfb-run some-daft-gui-script

and provided your script finishes cleanly and doesn't get stuck in a GUI dialogue, you are back at a prompt.

 
Search for Posts
2014
 
2013
 
2012
 
2011
 
2010
 
 
© 2013 Andy Ferguson