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:
#!/bin/sh XVFB=/usr/bin/Xvfb XVFBARGS=":1 -screen 0 1024x768x24 -ac +extension GLX +render -noreset -nolisten tcp" PIDFILE=/var/run/xvfb.pid case "$1" in start) echo -n "Starting virtual X frame buffer: Xvfb" start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS echo "." ;; stop) echo -n "Stopping virtual X frame buffer: Xvfb" start-stop-daemon --stop --quiet --pidfile $PIDFILE echo "." ;; restart) $0 stop $0 start ;; *) echo "Usage: /etc/init.d/xvfb {start|stop|restart}" exit 1 esac 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.