Automatically start a headless Selenium server on Ubuntu 11.04

This article is based on Running Selenium on headless Ubuntu 11.04 (like Ubuntu Server) with Xvfb.

Create the file /etc/init.d/xvfb with the following content:

#!/bin/bash

if [ -z "$1" ]; then
echo "`basename $0` {start|stop}"
exit
fi

case "$1" in
start)
/usr/bin/Xvfb :15 -ac -screen 0 1024x768x8 &
export DISPLAY=localhost:15.0
;;

stop)
killall Xvfb
;;
esac

Create the file /etc/init.d/selenium with the content below and change the path to Selenium server jar file:

#!/bin/bash

case "${1:-''}" in
	'start')
		if test -f /tmp/selenium.pid
		then
			echo "Selenium is already running."
		else
			export DISPLAY=localhost:15.0
			java -jar /path/to/selenium-server-standalone-2.4.0.jar > /tmp/selenium.log & echo $! > /tmp/selenium.pid
			echo "Starting Selenium..."

			error=$?
			if test $error -gt 0
			then
				echo "${bon}Error $error! Couldn't start Selenium!${boff}"
			fi
		fi
	;;
	'stop')
		if test -f /tmp/selenium.pid
		then
		echo "Stopping Selenium..."
		PID=`cat /tmp/selenium.pid`
		kill -3 $PID
		if kill -9 $PID ;
		then
			sleep 2
			test -f /tmp/selenium.pid && rm -f /tmp/selenium.pid
		else
			echo "Selenium could not be stopped..."
		fi
		else
		        echo "Selenium is not running."
		fi
		;;
	'restart')
		if test -f /tmp/selenium.pid
		then
			kill -HUP `cat /tmp/selenium.pid`
			test -f /tmp/selenium.pid && rm -f /tmp/selenium.pid
			sleep 1
			export DISPLAY=localhost:15.0
			java -jar /path/to/selenium-server-standalone-2.4.0.jar > /tmp/selenium.log & echo $! > /tmp/selenium.pid
			echo "Reload Selenium..."
		else
			echo "Selenium isn't running..."
		fi
		;;
	*)	# no parameter specified
		echo "Usage: $SELF start|stop|restart|reload|force-reload|status"
		exit 1
	;;
esac

Make the files executable and add them to start up:

sudo chmod +x /etc/init.d/xvfb
sudo chmod +x /etc/init.d/selenium
sudo update-rc.d xvfb defaults 10
sudo update-rc.d selenium defaults

Source: Init script for Selenium

Dette innlegget ble publisert i Selenium og merket med , , , , , , . Bokmerk permalenken.

En kommentar til Automatically start a headless Selenium server on Ubuntu 11.04

  1. Tilbaketråkk: Running Selenium on headless Ubuntu 11.04 (like Ubuntu Server) with Xvfb | Hnygard.no

Det er stengt for kommentarer.