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:
su - su - username
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
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
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:
and provided your script finishes cleanly and doesn’t get stuck in a GUI dialogue, you are back at a prompt.