4

I have a small program that checks some elements of a web service. The program shows graphics output and displays commmand-line results as well.

I have been trying to automate this program to run periodically on a server in my office. Problem is, It only works when I have X enabled - either directly on the server, or via SSH -X.

Following Google, I have tried Xvfb, which gave me quite cryptic error message:

Xvfb :1 -screen 0 1600x1200x32

Fatal server error:
Server is already active for display 1
        If this server is no longer running, remove /tmp/.X1-lock
        and start again.

Any ideas how to run it? I'm actually looking for the X equivalent of &>/dev/null...

studiohack
  • 13,477
Adam Matan
  • 8,740

4 Answers4

3

I had a similar problem and while Alex Morega's answer is fine, I liked this one better:

After installing xvfb, you can solve that in a single line: "xvfb-run <command>", where <command> is your program.

Source

Jonny
  • 133
3

In Ubuntu, echo $DISPLAY probably yields :0.0, telling you your Ubuntu session is using display 0. That should leave any other number for you to use. So, :1 should have been fine, unless there's still some Xvfb running from a previous test? (Or, like the error states: unless some temporary file /tmp/.X1-lock was not removed after some earlier test.) But: if you cannot figure out what is using display 1, then any other higher number should do as well.

A quick test in a fresh Ubuntu 9.10:

# Install once, if required:
sudo apt-get install xvfb
sudo apt-get install imagemagick

# Run Xvfb in the background, on display 1
Xvfb :1 &

# Run xclock in the background, on display 1
DISPLAY=:1 xclock &

# Make a screen capture of the window with name Xclock
DISPLAY=:1 import -window Xclock current-time.png

# Stop xclock
kill `pidof xclock`

# Stop Xvfb
kill `pidof Xvfb`

This should create a file current-time.png showing the current time. Does this work for you?

Arjan
  • 31,511
2

You could create a VNC display. VNC is intended for doing remote desktop: on the server end, it creates a virtual X display which renders in memory (it doesn't even need a video card), and you can connect to it remotely using a VNC client.

The Ubuntu package is named vnc4server in Universe. You can start up a display using the following command:

vnc4server :10

When you run it for the first time it asks you for a password, but since you don't need to connect to the display remotely, you can enter anything. Note that this opens a port on your machine (5910 in this example) which can be used to connect to this new X display, it would be wise to firewall it.

Now run the cron script with DISPLAY=:10.0 in its environment, and it should use the VNC display.

0

It looks like your server is running in runlevel 5 (X11 active). What you may want is a runlevel without that, so try 3 to run Xvfb? (assuming you do not run Ubuntu, in which case this can get ugly)