Skip to content

Instantly share code, notes, and snippets.

@carlosantoniodasilva
Created April 6, 2011 17:49
Show Gist options
  • Save carlosantoniodasilva/906129 to your computer and use it in GitHub Desktop.
Save carlosantoniodasilva/906129 to your computer and use it in GitHub Desktop.
Running Capybara + Webdriver with Xvfb in a CI server (linux)
## rake command
RAILS_ENV=test DISPLAY=:2.0 rake db:migrate spec:acceptance
## init.d
#!/bin/sh
### BEGIN INIT INFO
# Provides: xvfb
# Required-Start: $syslog $local_fs $network
# Required-Stop: $syslog $local_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1
# Description: Handles Xvfb server to run firefox in selenium specs
### END INIT INFO
. /lib/lsb/init-functions
DISPLAY=:2.0
NAME=Xvfb
INSTALL_DIR=/usr/bin
DAEMON=$INSTALL_DIR/$NAME
DAEMON_ARGS="-ac -screen scrn 1024x768x24 $DISPLAY"
PIDFILE=/var/run/$NAME.pid
DAEMON_USER=root
DAEMON_GROUP=$DAEMON_USER
# test -f $DAEMON || exit 0
# test -f $PROJECT_DIR || exit 0
case "$1" in
start)
log_daemon_msg "Starting xvfb" "xvfb"
start-stop-daemon --background --make-pidfile --exec $DAEMON --start --name $NAME --pidfile $PIDFILE --chuid $DAEMON_USER:$DAEMON_GROUP -- $DAEMON_ARGS
log_end_msg $?
;;
stop)
log_daemon_msg "Stopping xvfb" "xvfb"
start-stop-daemon --stop --pidfile $PIDFILE --quiet --retry 10
log_end_msg $?
;;
restart)
log_daemon_msg "Restarting xvfb" "xvfb"
start-stop-daemon --stop --pidfile $PIDFILE --quiet --retry 10
start-stop-daemon --background --make-pidfile --exec $DAEMON --start --name $NAME --pidfile $PIDFILE --chuid $DAEMON_USER:$DAEMON_GROUP -- $DAEMON_ARGS
log_end_msg $?
;;
status)
status_of_proc $DAEMON $NAME && exit 0 || exit $?
;;
*)
log_action_msg "Usage: /etc/init.d/xvfb (start|stop|restart)"
exit 2
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment