Skip to content

Instantly share code, notes, and snippets.

@maanas
Last active August 29, 2015 13:56
Show Gist options
  • Save maanas/9036603 to your computer and use it in GitHub Desktop.
Save maanas/9036603 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# /etc/rc.d/init.d/selenium
#
# chkconfig: 345 95 28
# description: Starts/Stops Selenium server
# processname: selenium
#
. /etc/init.d/functions
[ "${NETWORKING}" = "no" ] && exit 0
case "${1:-''}" in
'start')
if test -f /opt/selenium/selenium.pid
then
echo "Selenium is already running."
else
DISPLAY=:7 java -jar /opt/selenium/selenium-server-standalone-2.39.0.jar -port 4444 > /opt/selenium/selenium-output.log 2> /opt/selenium/selenium-error.log & echo $! > /opt/selenium/selenium.pid
echo "Starting Selenium..."
error=$?
if test $error -gt 0
then
echo "${bon}Error $error! Couldn't start Selenium!${boff}"
echo_success
fi
fi
;;
'stop')
if test -f /opt/selenium/selenium.pid
then
echo "Stopping Selenium..."
PID=`cat /opt/selenium/selenium.pid`
kill -3 $PID
if kill -9 $PID ;
then
sleep 2
test -f /opt/selenium/selenium.pid && rm -f /opt/selenium/selenium.pid
else
echo "Selenium could not be stopped..."
fi
else
echo "Selenium is not running."
fi
;;
'restart')
if test -f /opt/selenium/selenium.pid
then
kill -HUP `cat /opt/selenium/selenium.pid`
test -f /opt/selenium/selenium.pid && rm -f /opt/selenium/selenium.pid
sleep 1
java -jar /opt/selenium/selenium-server-standalone-2.39.0.jar -port 4444 > /opt/selenium/selenium-output.log 2> /opt/selenium/selenium-error.log & echo $! > /opt/selenium/selenium.pid
echo "Reload Selenium..."
else
echo "Selenium isn't running..."
fi
;;
'status')
if test -f $pid_file
then
PID=`cat /opt/selenium/selenium.pid`
if ps --pid $PID >/dev/null ;
then
echo "Selenium is running...$PID"
else
echo "Selenium isn't running..."
fi
else
echo "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