#!/bin/bash
#
#
#  selenium   startup script for selenium
#
# chkconfig: - 97 03
# description: Selenium Remote Control server use to launch Selenium tests

#[ -r /etc/sysconfig/selenium ] && . /etc/sysconfig/selenium

JAVA_PROG=java
SELENIUM_JAR=/root/ovirt/selenium/selenium-server-1.0/selenium-server.jar
FIREFOX_PROFILE_DIR=/root/ovirt/selenium-firefox-profile/

PID_FILE=/var/run/selenium.pid

RETVAL=0

. /etc/init.d/functions

start() {
   echo -n "Starting Selenium"
   export DISPLAY=:5
   $JAVA_PROG -jar $SELENIUM_JAR -firefoxProfileTemplate $FIREFOX_PROFILE_DIR&
   RETVAL=$?
   echo $! > $PID_FILE
   if [ $RETVAL -eq 0 ]; then
       echo_success
       echo
   else
       echo_failure
       echo
   fi
}

stop() {
  echo -n "Stopping Selenium"
  PID=`cat $PID_FILE`
  kill $PID
  rm -f $PID_FILE
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
       ;;
    *)
      echo "Usage: selenium {start|stop|restart}"
      exit 1
  ;;
esac

exit $RETVAL
