Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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...

share|improve this question
add comment

4 Answers 4

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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?

share|improve this answer
    
You'll want to save the PIDs using cmd & cmd_pid=$! and kill them specifically to avoid taking out any innocent bystanders. –  l0b0 Apr 25 at 15:32
add comment

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

share|improve this answer
add comment

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)

share|improve this answer
    
Thanks. I'm actually using Ubuntu, and trying 3 gave me "Fatal server error: Couldn't add screen 0". –  Adam Matan Oct 22 '09 at 14:06
    
Yeah, Ubuntu has some weird configuration for the runlevels. Default runlevel is 2, I think, and there seems to be no runlevel without X11 running. If you are unsure about the runlevels, read up on the docs. –  brandstaetter Oct 23 '09 at 6:35
    
@brandstaetter: in Debian & Ubuntu, runlevels 2-5 are identical (system boots to runlevel 2). runlevel 1 is the single-user "recovery mode", no X there. –  quack quixote Dec 1 '09 at 1:13
    
Thanks. But there is no multi user mode without X11, still :( –  brandstaetter Dec 1 '09 at 7:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.