Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I’ve got a Debian web server that I’m using for occasional screen-scraping via Selenum and Python.

I use Xvfb as a virtual X server for Firefox to run on when being controlled by Selenium. Given that I (think) I have to start this using sudo, I don’t think it’ll be feasible to start it from Python each time (see my Stack Overflow question), so I figured I could just have it running all the time.

I currently start it like this at the command line:

sudo Xvfb :99 -nolisten tcp -fbdir /var/run

What method should I use to do this automatically at startup? Should I use cron, as suggested here?

share|improve this question
up vote 6 down vote accepted

On debian, you can add the Xvfb command to /etc/rc.local. If Xvfb doesn't detach itself into the background, use an & on the end of the command.

Using cron would work too, although init scripts give you more control over exactly when in the startup sequence it will run, and are the traditional way of starting services.

share|improve this answer
Aha, excellent. Is editing /etc/rc.local preferred to using update-rc.d with one’s own individual scripts? – Paul D. Waite Apr 1 '11 at 21:36
@Paul I would say update-rc.d is preferred and is certainly more capable, but rc.local is quicker and easier. Also, I think Gilles is right, there's no reason this needs to run as root. – Andy Apr 1 '11 at 22:31

Your premise is invalid: there is no reason to run Xvfb as root. Your usual X server only needs to run as root (on many but not all unices) only so that it can access the video hardware; that's not an issue for Xvfb by definition.

If you want to run Xvfb at startup, you can use cron with @reboot replacing the five date-and-time fields. You can do that in any user's crontab, not just root's. But I don't see the point. Your scripts would be more robust if you started Xvfb when you need it, just the way you seem to have originally planned it.

share|improve this answer

As @Gilles suggested, it's more suitable to run on demand, especially when you're using it for Selenium testing. Here is example shell commands:

export DISPLAY=:99
xdpyinfo -display $DISPLAY > /dev/null || Xvfb $DISPLAY -screen 0 1024x768x16 &

Checking display using xdpyinfo before will make sure you won't run virtual framebuffer twice.

If you really need to start it on startup, you can try the following init.d script:

XVFBARGS=":1 -screen 0 1024x768x24 -ac +extension GLX +render -noreset -nolisten tcp"
case "$1" in
    echo -n "Starting virtual X frame buffer: Xvfb"
    start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
    echo "."
    echo -n "Stopping virtual X frame buffer: Xvfb"
    start-stop-daemon --stop --quiet --pidfile $PIDFILE
    echo "."
    $0 stop
    $0 start
        echo "Usage: /etc/init.d/xvfb {start|stop|restart}"
        exit 1

exit 0

Source: dloman/xvfb at GitHub (forked from: jterrace/xvfb)

Save it as /etc/init.d/xvfb and make it executable, then start it as:

/etc/init.d/xvfb start

To automatically run on startup, run:

sudo update-rc.d xvfb defaults

To remove it from autorun, run:

sudo update-rc.d -f xvfb remove

Also add to environment file to be recognized by X programs, e.g.:

echo DISPLAY=":1" | sudo tee -a /etc/environment

Here is version for systemd version: dloman/xvfb.service.

share|improve this answer

Your Answer


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.