Skip to content

Instantly share code, notes, and snippets.

@tspycher
Last active December 28, 2015 02:49
Show Gist options
  • Save tspycher/7430750 to your computer and use it in GitHub Desktop.
Save tspycher/7430750 to your computer and use it in GitHub Desktop.
/etc/init.d/selenium for CentoOS 6.4
#!/bin/bash
# selenium - this script starts and stops the selenium grid
#
# chkconfig: - 85 15
# description: Selenium Grid is a distributed testing platform for browser-based automation.
# processname: selenium
# pidfile: /etc/selenium/tmp/selenium.pid
# Source function library.
. /etc/rc.d/init.d/functions
selenium_dir=/opt
log_dir=/etc/selenium/logs
error_log=$log_dir/selenium_error.log
std_log=$log_dir/selenium_std.log
pid_file=/etc/selenium/selenium.pid
java=/usr/bin/java
selenium="$selenium_dir/selenium-server-standalone"
xvfb=/usr/bin/Xvfb
xvfb_params=":99 -ac -screen 0 1024x768x8"
user=selenium
role=node
start() {
if test -f $pid_file
then
PID=`cat $pid_file`
if ps --pid $PID >/dev/null;
then
echo "Selenium is already running: $PID"
exit 0
else
echo "Removing stale pid file: $pid_file"
fi
fi
echo -n "Starting Selenium..."
su $user -c "DISPLAY=:99 $java -jar $selenium -role $role -${role}Config /etc/selenium/${role}.config >$std_log 2>$error_log &"
if [ $? == "0" ]; then
success
else
failure
fi
echo
ps -C java -o pid,cmd | grep $selenium | awk {'print $1 '} > $pid_file
if test -f $xvfb
then
echo "Starting xvfB"
${xvfb} ${xvfb_params} >/dev/null 2>/dev/null &
fi
}
stop() {
if test -f $pid_file
then
echo -n "Stopping Selenium..."
PID=`cat $pid_file`
su $user -c "kill -3 $PID"
if kill -9 $PID ;
then
sleep 2
test -f $pid_file && rm -f $pid_file
success
else
echo "Selenium could not be stopped..."
failure
fi
else
echo "Selenium is not running."
failure
fi
if [ -f ${xvfb} ]
then
killall Xvfb || true
fi
echo
}
status() {
if test -f $pid_file
then
PID=`cat $pid_file`
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
}
case "$1" in
start)
$1
;;
stop)
$1
;;
restart)
stop
start
;;
status)
$1
;;
*)
echo "Usage: $SELF start|stop|restart|status"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment