Skip to content

Instantly share code, notes, and snippets.

@generalredneck
Created June 22, 2012 22:00
Show Gist options
  • Save generalredneck/2975447 to your computer and use it in GitHub Desktop.
Save generalredneck/2975447 to your computer and use it in GitHub Desktop.
seleniem service
SELENIUM_DIR='/usr/lib/headless-selenium'
SELENIUM_PROFILE_DIR=$SELENIUM_DIR/profiles/firefox/selenium
SELENIUM_JAR=$SELENIUM_DIR/selenium-server-standalone-2.24.1.jar
SELENIUM_LOG_DIR='/var/log/selenium'
DISPLAY=:42
if [ "$XVFB_SCREEN_GEOMETY" = "" ]
then
XVFB_SCREEN_GEOMETRY=1024x768x24
fi
case "${1:-''}" in
'start')
if test -f /tmp/selenium.pid
then
echo "Headless Selenium is already running."
else
echo "Starting Xvfb..."
Xvfb $DISPLAY -screen 0 $XVFB_SCREEN_GEOMETRY >> $SELENIUM_LOG_DIR/Xvfb-output.log 2>> $SELENIUM_LOG_DIR/Xvfb-error.log & echo $! > /tmp/Xvfb.pid
error=$?
if test $error -gt 0
then
echo "${bon}Error $error! Couldn't start Xvfb!${boff}"
exit
fi
DISPLAY=$DISPLAY java -jar $SELENIUM_JAR -port 4444 -firefoxProfileTemplate $SELENIUM_PROFILE_DIR >> $SELENIUM_LOG_DIR/selenium-output.log 2>> $SELENIUM_LOG_DIR/selenium-error.log & echo $! > /tmp/selenium.pid
echo "Starting Selenium..."
error=$?
if test $error -gt 0
then
echo "${bon}Error $error! Couldn't start Selenium!${boff}"
exit
fi
fi
;;
'stop')
if test -f /tmp/selenium.pid
then
echo "Stopping Headless Selenium..."
SELENIUM_PID=`cat /tmp/selenium.pid`
XVFB_PID=`cat /tmp/Xvfb.pid`
kill -3 $SELENIUM_PID
kill -3 $XVFB_PID
if kill -9 $SELENIUM_PID ;
then
sleep 2
test -f /tmp/Xvfb.pid && rm -f /tmp/Xvfb.pid
test -f /tmp/selenium.pid && rm -f /tmp/selenium.pid
else
echo "Selenium could not be stopped..."
fi
else
echo "Headless Selenium is not running."
fi
;;
'restart')
if test -f /tmp/selenium.pid
then
$0 stop
sleep 1
echo "Reload Headless Selenium..."
$0 start
else
echo "Headless Selenium isn't running..."
fi
;;
*) # no parameter specified
echo "Usage: $SELF start|stop|restart|reload|force-reload|status"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment