Merge branch 'lab/selenium-docker' into 'develop'

updates on pwrd, simplified

See merge request artica/pandorafms!2045

Former-commit-id: cfae76c639904ce34f2512ca1e4661826912c8eb
This commit is contained in:
vgilc 2018-12-05 08:33:47 +01:00
commit e6bac9a195
8 changed files with 367 additions and 116 deletions

View File

@ -0,0 +1,21 @@
{
"capabilities": [
{
"browserName": "*firefox",
"maxInstances": 1,
"seleniumProtocol": "Selenium"
},
{
"browserName": "firefox",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
}
],
"configuration": {
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 1,
"port": 5555,
"register": true,
"registerCycle": 5000
}
}

View File

@ -0,0 +1,20 @@
# Sample PWRD crontab control tweaks
# Do not allow firefox running for more than 1h
0 * * * * root /opt/pwrd_maintenance.sh -k
# Force node-start
*/5 * * * * root /opt/pwrd_maintenance.sh -s
# Reset firefox version if does not match required 47.0.1
* * * * * root /opt/pwrd_maintenance.sh -f
# Restart node if java process is not found
* * * * * root /opt/pwrd_maintenance.sh -r
# Restart node if no activity since last check
*/5 * * * * root /opt/pwrd_maintenance.sh -c1
# Restart node if connection have been lost to hub
*/5 * * * * root /opt/pwrd_maintenance.sh -c2

View File

@ -0,0 +1,52 @@
#!/bin/bash
#
# Sample PWRD maintenance script
# **********************************************************************
# **********************************************************************
# Settings
hub_ip="192.168.1.10"
hub_port="4444"
# Customize PWR global installation directory
PWR_FIREFOX_INSTALLDIR="/opt"
# **********************************************************************
if [ "$1" == "-k" ]; then
killall --older-than 1h firefox >/dev/null 2>&1
elif [ "$1" == "-s" ]; then
/etc/init.d/pwrd start-node http://$hub_ip:$hub_port/grid/register > /dev/null 2>&1
elif [ "$1" == "-f" ]; then
if [ "`firefox --version`" != "Mozilla Firefox 47.0.1" ]; then
$PWR_FIREFOX_INSTALLDIR/restore_firefox.sh >/dev/null 2>&1
echo `date +"%c"` Firefox restored > /tmp/restore_firefox.log
[`/etc/init.d/pwrd status | grep "Node is running" | wc -l` -eq 1 ] && /etc/init.d/pwrd restart-node http://$hub_ip:$hub_port/grid/register > /dev/null 2>&1
[`/etc/init.d/pwrd status | grep "PWRD is running" | wc -l` -eq 1 ] && /etc/init.d/pwrd restart > /dev/null 2>&1
fi
elif [ "$1" == "-r" ]; then
if [ ` ps aux | grep "java -jar" | grep -v grep | wc -l` -lt 1 ]; then
[`/etc/init.d/pwrd status | grep "Node is running" | wc -l` -eq 1 ] && /etc/init.d/pwrd restart-node http://$hub_ip:$hub_port/grid/register > /dev/null 2>&1
[`/etc/init.d/pwrd status | grep "PWRD is running" | wc -l` -eq 1 ] && /etc/init.d/pwrd restart > /dev/null 2>&1
echo `date +"%c"` PWRD restarted, java process not found > /tmp/pwrd_restart_detected.log
fi
elif [ "$1" == "-c1" ]; then
if [ $(/etc/pandora/plugins/grep_log /var/log/pwr/pwr_std.log check_pwrd ".*" | wc -l) -eq 0 ]; then
[`/etc/init.d/pwrd status | grep "Node is running" | wc -l` -eq 1 ] && /etc/init.d/pwrd restart-node http://$hub_ip:$hub_port/grid/register > /dev/null 2>&1
[`/etc/init.d/pwrd status | grep "PWRD is running" | wc -l` -eq 1 ] && /etc/init.d/pwrd restart > /dev/null 2>&1
echo $(date +"%c") PWRD restarted, no output detected in log > /tmp/pwrd_restart_detected.log
fi
elif [ "$1" == "-c2" ]; then
if [ $(/etc/pandora/plugins/grep_log /var/log/pwr/pwr_std.log check_pwrd_err_conn "refused" | grep "$hub_ip:$hub_port [/$hub_ip] failed:" | wc -l) -gt 0 ]; then
/etc/init.d/pwrd restart-node http://$hub_ip:$hub_port/grid/register > /dev/null 2>&1
echo $(date +"%c") PWRD restarted, lost connection with hub > /tmp/pwrd_restart_detected.log
fi
fi

View File

@ -0,0 +1,20 @@
#!/bin/bash
#
# Script to restore firefox to tar
#
# **********************************************************************
# Customize PWR global installation directory
PWR_FIREFOX_INSTALLDIR="/opt"
cd $PWR_FIREFOX_INSTALLDIR
if [ -f firefox-47.0.1.tar ]; then
rm -rf firefox-47 >/dev/null 2>&1
mv firefox firefox_ >/dev/null 2>&1
tar xvf firefox-47.0.1.tar >/dev/null 2>&1
mv firefox firefox-47 >/dev/null 2>&1
mv firefox_ firefox >/dev/null 2>&1
else
echo "firefox-47.0.1.tar not found, please leave a copy at $PWR_FIREFOX_INSTALLDIR"
fi

View File

@ -0,0 +1 @@
4881ba55982d75040775bafdffcdf57b2cd7ea13

112
pandora_server/util/pwrd/install_pwrd.sh Normal file → Executable file
View File

@ -1,7 +1,6 @@
#!/bin/bash #!/bin/bash
if [ "$1" == "" ] || [ "$1" != "--install" ]; then HELP=`cat<<_HELP
cat<<_HELP
********************** **********************
PWR Server installer PWR Server installer
********************** **********************
@ -9,44 +8,91 @@ if [ "$1" == "" ] || [ "$1" != "--install" ]; then
To install the Pandora web robot daemon (pwrd) To install the Pandora web robot daemon (pwrd)
Please launch this script as root: Please launch this script as root:
$0 --install $0 --install [[user] [directory]]
_HELP _HELP
`
if [ "$1" == "" ] || [ "$1" != "--install" ]; then
echo "$HELP"
exit 0 exit 0
fi fi
if [ "`rpm -qa | grep xorg-x11-server-Xvfb | wc -l`" == "0" ]; then if [ "`which rpm`" ]; then
if [ "`rpm -qa | grep xorg-x11-server-Xvfb | wc -l`" == "0" ]; then
echo "Package xorg-x11-server-Xvfb is required" echo "Package xorg-x11-server-Xvfb is required"
exit 0 exit 0
fi
else
echo "Xvfb is required, please confirm is installed in your system"
fi
# default user is running user
GLOBAL_INST_USER=`whoami`
if [ "$2" != "" ]; then
if [ `cat /etc/passwd | cut -f1 -d':' | grep -w "$2" | wc -l` -gt 0 ]; then
GLOBAL_INST_USER=$2
elif [ -d "$2" ]; then
GLOBAL_INST_DIR=$2
else
echo "Cannot use \"$2\" as user nor directory"
echo "$HELP"
exit 0
fi
fi
if [ "$3" != "" ]; then
if [ -d "$3" ]; then
GLOBAL_INST_DIR=$3
elif [ `cat /etc/passwd | cut -f1 -d':' | grep -w "$3" | wc -l` -gt 0 ]; then
GLOBAL_INST_USER=$3
else
echo "Cannot use \"$3\" as directory nor user"
echo "$HELP"
exit 0
fi
fi fi
chmod +x pwrd chmod +x pwrd
PWR_SERVER_DEST=/usr/lib/pwr PWR_SERVER_DEST=$GLOBAL_INST_DIR/usr/lib/pwr
PWR_SERVER_RSC=/etc/pwr/tmp PWR_SERVER_RSC=$GLOBAL_INST_DIR/etc/pwr/tmp
PWR_SERVER_LOG=/var/log/pwr PWR_SERVER_LOG=$GLOBAL_INST_DIR/var/log/pwr
PWR_FIREFOX_INSTALLDIR=/opt PWR_FIREFOX_INSTALLDIR=$GLOBAL_INST_DIR/opt
mkdir -p $PWR_SERVER_DEST PWR_FIREFOX_INSTALLDIR_ESCAPED=`echo $PWR_FIREFOX_INSTALLDIR | sed 's/\\//\\\\\//g'`
mkdir -p $PWR_SERVER_LOG GLOBAL_INST_DIR_ESCAPED=`echo $GLOBAL_INST_DIR | sed 's/\\//\\\\\//g'`
mkdir -p $PWR_SERVER_RSC
mkdir -p $PWR_FIREFOX_INSTALLDIR
[ -d $PWR_SERVER_DEST ] || mkdir -p $PWR_SERVER_DEST
[ -d $PWR_SERVER_LOG ] || mkdir -p $PWR_SERVER_LOG
[ -d $PWR_SERVER_RSC ] || mkdir -p $PWR_SERVER_RSC
[ -d $PWR_FIREFOX_INSTALLDIR ] || mkdir -p $PWR_FIREFOX_INSTALLDIR
[ -d $GLOBAL_INST_DIR/etc/init.d ] || mkdir -p $GLOBAL_INST_DIR/etc/init.d
tar xvf firefox-43.0.tar >/dev/null tar xvf firefox-47.0.1.tar >/dev/null
mv firefox $PWR_FIREFOX_INSTALLDIR/ mv firefox $PWR_FIREFOX_INSTALLDIR/firefox-47
ln -s $PWR_FIREFOX_INSTALLDIR/firefox-47/firefox $PWR_FIREFOX_INSTALLDIR/firefox
tar xvzf firefox_profile.tar.gz >/dev/null tar xvzf firefox_profile.tar.gz >/dev/null
chown -R `whoami`. firefox_profile if [ $? -ne 0 ]; then
mv firefox_profile $PWR_FIREFOX_INSTALLDIR echo "Failed to deploy firefox profile, please retry installation"
exit 1
fi
chown -R "$GLOBAL_INST_USER". firefox_profile
[ ! -d "$PWR_FIREFOX_INSTALLDIR/firefox_profile" ] && mv firefox_profile $PWR_FIREFOX_INSTALLDIR
ln -s $PWR_FIREFOX_INSTALLDIR/firefox/firefox /usr/bin/firefox [ -d "$PWR_FIREFOX_INSTALLDIR/selenium" ] || mkdir -p $PWR_FIREFOX_INSTALLDIR/selenium
cp config.json $PWR_FIREFOX_INSTALLDIR/selenium/
ln -s $PWR_FIREFOX_INSTALLDIR/firefox /usr/bin/firefox
# Generate logrotate configuration # Generate logrotate configuration
echo <<EO_LROTATE > /etc/logrotate.d/pwrd
cat > /etc/logrotate.d/pwrd <<EO_LROTATE
/var/log/pwr/pwr_std.log /var/log/pwr/pwr_std.log
/var/log/pwr/xvfb.log
/var/log/pwr/pwr_error.log { /var/log/pwr/pwr_error.log {
weekly weekly
missingok missingok
@ -60,10 +106,35 @@ cat > /etc/logrotate.d/pwrd <<EO_LROTATE
EO_LROTATE EO_LROTATE
cp ./extras/restore_firefox.sh $PWR_FIREFOX_INSTALLDIR/
cp ./extras/pwrd_maintenance.sh $PWR_FIREFOX_INSTALLDIR/
cp ./selenium-server-standalone-2.53.1.jar $PWR_SERVER_DEST/ cp ./selenium-server-standalone-2.53.1.jar $PWR_SERVER_DEST/
cp ./pwrd /etc/init.d/pwrd cp ./pwrd /etc/init.d/pwrd
cp ./pwrd $GLOBAL_INST_DIR/etc/init.d/pwrd
chmod +x /etc/init.d/pwrd chmod +x /etc/init.d/pwrd
# Update pwrd daemon
if [ "$GLOBAL_INST_DIR" != "" ]; then
echo "Adjusting pwrd global directory to: $GLOBAL_INST_DIR"
sed -i "s/PWR_GLOBAL_DIR=\"\"/PWR_GLOBAL_DIR=\"$GLOBAL_INST_DIR_ESCAPED\"/g" /etc/init.d/pwrd
sed -i "s/PWR_GLOBAL_DIR=\"\"/PWR_GLOBAL_DIR=\"$GLOBAL_INST_DIR_ESCAPED\"/g" $GLOBAL_INST_DIR/etc/init.d/pwrd
echo "Adjusting pwrd_maintenance global directory to: $PWR_FIREFOX_INSTALLDIR"
sed -i "s/PWR_FIREFOX_INSTALLDIR=\"\/opt\"/PWR_FIREFOX_INSTALLDIR=\"$PWR_FIREFOX_INSTALLDIR_ESCAPED\"/g" $PWR_FIREFOX_INSTALLDIR/pwrd_maintenance.sh
echo "Adjusting restore_firefox global directory to: $PWR_FIREFOX_INSTALLDIR"
sed -i "s/PWR_FIREFOX_INSTALLDIR=\"\/opt\"/PWR_FIREFOX_INSTALLDIR=\"$PWR_FIREFOX_INSTALLDIR_ESCAPED\"/g" $PWR_FIREFOX_INSTALLDIR/restore_firefox.sh
fi
if [ "$GLOBAL_INST_USER" != "" ]; then
echo "Adjusting pwrd global user to: $GLOBAL_INST_USER"
sed -i "s/USER=\"root\"/USER=\"$GLOBAL_INST_USER\"/g" /etc/init.d/pwrd
sed -i "s/USER=\"root\"/USER=\"$GLOBAL_INST_USER\"/g" $GLOBAL_INST_DIR/etc/init.d/pwrd
fi
[ "$GLOBAL_INST_USER" != "" ] && chown -R "$GLOBAL_INST_USER". $PWR_SERVER_DEST
[ "$GLOBAL_INST_USER" != "" ] && chown -R "$GLOBAL_INST_USER". $PWR_SERVER_LOG
[ "$GLOBAL_INST_USER" != "" ] && chown -R "$GLOBAL_INST_USER". $PWR_SERVER_RSC
cat <<EOF cat <<EOF
********************* *********************
PWR Server deployed PWR Server deployed
@ -71,10 +142,9 @@ cat <<EOF
Succesfully installed! Succesfully installed!
Please start the service with: Now you can start the service with:
/etc/init.d/pwrd start /etc/init.d/pwrd start
EOF EOF

View File

@ -1,9 +1,25 @@
#!/bin/bash #!/bin/bash
# pwr - this script starts and stops the pwr grid
# **********************************************************************
# Pandora FMS PWR Server Daemon
# (c) 2008-2018 Artica ST
# #
# chkconfig: - 85 1# description: PWRD Grid is a distributed testing platform for browser-based automation. # Please see http://www.pandorafms.org
# **********************************************************************
### BEGIN INIT INFO
# Provides: pwrd
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 5
# Default-Stop: 0 1 6
# Short-Description: Startup script daemon for PWR server
# Description: Startup script daemon for PWR server (linux)
### END INIT INFO
# chkconfig: - 85 1
# description: PWRD Grid is a distributed platform for browser-based automation.
# processname: pwr # processname: pwr
# pidfile: $base_dir/pwr.pid
# Source function library. # Source function library.
@ -12,21 +28,55 @@ if [ -e /etc/rc.d/init.d/functions ]; then
fi fi
pwr_dir=/usr/lib/pwr # **********************************************************************
log_dir=/var/log/pwr # Configuration options
std_log=$log_dir/pwr_std.log # Example node capabilities: -browser browserName=firefox,maxInstances=1,platform=LINUX
base_dir=/etc/pwr/tmp
java=/usr/bin/java # Customize Java binary path
pwr="$pwr_dir/selenium-server-standalone-2.53.1.jar" JAVA=/usr/bin/java
# Following parameters will control node capabilities: -browser browserName=firefox,maxInstances=1,platform=LINUX
PWROPTS=" -firefoxProfileTemplate /opt/firefox_profile" # Customize PWR global installation directory
PWR_HUB_OPTS="" PWR_GLOBAL_DIR=""
user=root
xvfb_pid_file=$base_dir/xvfb.pid # Customize PWR running user
USER="root"
# Customize PWR application files directory
PWR_INST_DIR="$PWR_GLOBAL_DIR/opt"
# Customize port for PWR
PWR_PORT=4444
PWR_HUB_PORT=4444
PWR_NODE_PORT=5555
# Extra options for PWR
PWR_OPTS=" -firefoxProfileTemplate $PWR_INST_DIR/firefox_profile "
PWR_NODE_OPTS=" -nodeConfig $PWR_INST_DIR/selenium/config.json "
PWR_HUB_OPTS=""
# **********************************************************************
# Default paths
PWR_DIR="$PWR_GLOBAL_DIR/usr/lib/pwr"
LOG_DIR="$PWR_GLOBAL_DIR/var/log/pwr"
STD_LOG="$LOG_DIR/pwr_std.log"
BASE_DIR="$PWR_GLOBAL_DIR/etc/pwr/tmp"
PWR="$PWR_DIR/selenium-server-standalone-2.53.1.jar"
XVFB_PID_FILE="$BASE_DIR/xvfb.pid"
# **********************************************************************
# Variables
# Variable
host=`ip a show $(route -n | awk '/^0\.0\.0\.0/ {print $NF}') | grep "inet " | awk '{print $2}' | cut -f1 -d'/' | head -1` host=`ip a show $(route -n | awk '/^0\.0\.0\.0/ {print $NF}') | grep "inet " | awk '{print $2}' | cut -f1 -d'/' | head -1`
# **********************************************************************
# Functions
# Start Xvfb, required for firefox in server without X # Start Xvfb, required for firefox in server without X
function start_xvfb() { function start_xvfb() {
`which Xvfb >/dev/null 2>&1` `which Xvfb >/dev/null 2>&1`
@ -37,45 +87,48 @@ function start_xvfb() {
echo 1 echo 1
fi fi
else else
Xvfb :99 -ac > /dev/null 2>&1 & Xvfb :99 -screen 0 1400x768x24 -ac +extension RANDR > $LOG_DIR/xvfb.log 2>&1 & echo $! > $XVFB_PID_FILE
export DISPLAY=:99 export DISPLAY=:99
ps -eo pid,cmd | grep Xvfb | grep -v grep | awk {'print $1 '} > $xvfb_pid_file
echo 0 echo 0
fi fi
} }
# Stop Xvfb # Stop Xvfb
function stop_xvfb() { function stop_xvfb() {
if test -f $xvfb_pid_file ; then echo
if test -f $XVFB_PID_FILE ; then
# Check if there's more instances of pwrd running i.e. standalone + node # Check if there's more instances of pwrd running i.e. standalone + node
if [ ! -e "$base_dir/pwrd_node.pid" ] && [ ! -e "$base_dir/pwrd.pid" ]; then if [ ! -e "$BASE_DIR/pwrd_node.pid" ] && [ ! -e "$BASE_DIR/pwrd.pid" ]; then
if [ ! -e /etc/rc.d/init.d/functions ]; then
echo -n "Stopping Xvfb..." echo -n "Stopping Xvfb..."
PID=$(cat $xvfb_pid_file) fi
if [ `kill -9 $PID 2>&1 | grep "No such process" | wc -l` == "1" ]; then PID=$(cat $XVFB_PID_FILE)
if [ "$PID" != "" ] && [ `kill -9 $PID 2>&1 | grep "No such process" | wc -l` == "1" ]; then
# PID file exists but no process # PID file exists but no process
test -f $xvfb_pid_file && rm -f $xvfb_pid_file [ -f $XVFB_PID_FILE ] && rm -f $XVFB_PID_FILE
if [ -e /etc/rc.d/init.d/functions ]; then if [ -e /etc/rc.d/init.d/functions ]; then
success success
fi fi
return 0 return 0
fi fi
else else
echo "(1) pwrd process left. Skipping Xvfb" [ -e $BASE_DIR/pwrd_node.pid ] && echo -n `cat $BASE_DIR/pwrd_node.pid`
[ -e $BASE_DIR/pwrd.pid ] && echo -n `cat $BASE_DIR/pwrd.pid`
echo -e "\nThere're pwrd processes left. Skipping Xvfb"
fi fi
fi fi
} }
################################################################################
########################################################################
# START # START
################################################################################ ########################################################################
# Start Selenium Standalone server # Start Selenium Standalone server
function start() { function start() {
if test -f $pid_file if test -f $pid_file; then
then
PID=`cat $pid_file` PID=`cat $pid_file`
if ps --pid $PID >/dev/null; then if [ "$PID" != "" ] && ps --pid $PID >/dev/null; then
echo "PWRD is already running: $PID" echo "PWRD is already running: $PID"
exit 2 exit 2
else else
@ -91,11 +144,12 @@ function start() {
return 1 return 1
fi fi
if [ ! -e /etc/rc.d/init.d/functions ]; then
echo -n "Starting PWRD..." echo -n "Starting PWRD..."
fi
export DISPLAY=:99 export DISPLAY=:99
su $user -c "$java -jar $pwr -host $host $PWROPTS > $std_log 2>&1 &" PID=$(su $USER -c "$JAVA -jar $PWR -host $host -port $PWR_PORT $PWR_OPTS > $STD_LOG 2>&1 & echo \$!")
if [ $? == "0" ]; then if [ $? == "0" ]; then
if [ -e /etc/rc.d/init.d/functions ]; then if [ -e /etc/rc.d/init.d/functions ]; then
success success
@ -109,28 +163,29 @@ function start() {
fi fi
# Store PID # Store PID
ps -eo pid,cmd | grep $pwr | grep -v "node" | grep -v "hub" | grep -v grep | awk {'print $1 '} > $pid_file echo -n $PID > $pid_file
} }
# Start Selenium GRID server: HUB component # Start Selenium GRID server: HUB component
function start-hub() { function start-hub() {
if test -f $pid_file if test -f $pid_file; then
then
PID=`cat $pid_file` PID=`cat $pid_file`
if ps --pid $PID >/dev/null; then if [ "$PID" != "" ] && ps --pid $PID >/dev/null; then
echo "PWRD is already running: $PID" echo "PWRD is already running: $PID"
exit 2 exit 2
else else
echo "Removing stale pid file: $pid_file" echo "Removing stale pid file: $pid_file"
fi fi
fi fi
if [ ! -e /etc/rc.d/init.d/functions ]; then
echo -n "Starting PWRD..." echo -n "Starting PWRD..."
fi
# No Xvfb needed in hub mode # No Xvfb needed in hub mode
su $user -c "$java -jar $pwr -host $host -role hub $PWR_HUB_OPTS > $std_log 2>&1 &" PID=$(su $USER -c "$JAVA -jar $PWR -host $host -port $PWR_HUB_PORT -role hub $PWR_HUB_OPTS > $STD_LOG 2>&1 & echo \$!")
if [ $? == "0" ]; then if [ $? == "0" ]; then
if [ -e /etc/rc.d/init.d/functions ]; then if [ -e /etc/rc.d/init.d/functions ]; then
success success
@ -144,15 +199,17 @@ function start-hub() {
fi fi
# Store PID # Store PID
ps -eo pid,cmd | grep $pwr | grep "hub" | grep -v grep | awk {'print $1 '} > $pid_file echo -n $PID > $pid_file
echo
echo -e "Add nodes to HUB executing:\n $0 start-node http://$host:$PWR_HUB_PORT/grid/register"
} }
# Start Selenium GRID server: Node Connect to hub # Start Selenium GRID server: Node Connect to hub
function start-node() { function start-node() {
if test -f $pid_file if test -f $pid_file ; then
then
PID=`cat $pid_file` PID=`cat $pid_file`
if ps --pid $PID >/dev/null; then if [ "$PID" != "" ] && ps --pid $PID >/dev/null; then
echo "PWRD is already running: $PID" echo "PWRD is already running: $PID"
exit 2 exit 2
else else
@ -168,11 +225,12 @@ function start-node() {
return 1 return 1
fi fi
if [ ! -e /etc/rc.d/init.d/functions ]; then
echo -n "Starting PWRD..." echo -n "Starting PWRD..."
fi
export DISPLAY=:99 export DISPLAY=:99
su $user -c "$java -jar $pwr -host $host -role node -hub $1 $PWROPTS > $std_log 2>&1 &" PID=$(su $USER -c "$JAVA -jar $PWR -host $host -port $PWR_NODE_PORT -role node -hub $1 $PWR_OPTS > $STD_LOG 2>&1 & echo \$!")
if [ $? == "0" ]; then if [ $? == "0" ]; then
if [ -e /etc/rc.d/init.d/functions ]; then if [ -e /etc/rc.d/init.d/functions ]; then
success success
@ -186,34 +244,39 @@ function start-node() {
fi fi
# Store PID # Store PID
ps -C java -eo pid,cmd | grep $pwr | grep "node" | grep -v grep | awk {'print $1 '} > $pid_file echo -n $PID > $pid_file
} }
################################################################################
########################################################################
# STOP # STOP
################################################################################ ########################################################################
# Stop Selenium Standalone server # Stop Selenium Standalone server
function stop() { function stop() {
if test -f $pid_file ; then if test -f $pid_file ; then
echo -n "Stopping PWRD..." echo -n "Stopping PWRD..."
PID=$(cat $pid_file) PID=$(cat $pid_file)
su $user -c "kill -3 $PID" [ "$PID" == "" ] && PID=`ps aux | grep "$JAVA -jar $PWR" | grep -v grep | awk '{print $2}'`
kill -9 $PID >/dev/null 2>&1 [ "$PID" != "" ] && ps --pid $PID >/dev/null && su $USER -c "kill -3 $PID"
[ "$PID" != "" ] && ps --pid $PID >/dev/null && kill -9 $PID >/dev/null 2>&1
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
sleep 5 sleep 2
test -f $pid_file && rm -f $pid_file
if [ -e /etc/rc.d/init.d/functions ]; then if [ -e /etc/rc.d/init.d/functions ]; then
success success
fi fi
test -f $pid_file && rm -f $pid_file
stop_xvfb
else else
echo "PWRD could not be stopped..."
if [ -e /etc/rc.d/init.d/functions ]; then if [ -e /etc/rc.d/init.d/functions ]; then
failure failure
fi else
echo "Failed" echo "Failed"
fi fi
stop_xvfb fi
# Clean pid file
test -f $pid_file && rm -f $pid_file
else else
echo "PWRD is not running." echo "PWRD is not running."
stop_xvfb stop_xvfb
@ -224,84 +287,94 @@ function stop() {
echo echo
} }
################################################################################
########################################################################
# STATUS # STATUS
################################################################################ ########################################################################
# Status of Selenium Standalone server # Status of Selenium Standalone server
function status() { function status() {
mode=$1
if test -f $pid_file ; then if test -f $pid_file ; then
echo "checking: $pid_file"
PID=`cat $pid_file` PID=`cat $pid_file`
if ps --pid $PID >/dev/null ; then if [ "$PID" != "" ] && ps --pid $PID >/dev/null; then
echo "PWRD is running: $PID" echo "PWRD$mode is running: $PID"
if test -f $xvfb_pid_file ; then if test -f $XVFB_PID_FILE ; then
PID=`cat $xvfb_pid_file` PID=`cat $XVFB_PID_FILE`
if test -f $xvfb_pid_file ; then if test -f $XVFB_PID_FILE ; then
echo "Xvfb is running: $PID" echo "Xvfb is running: $PID"
fi fi
fi fi
else else
echo "PWRD isn't running..." echo "PWRD$mode isn't running..."
fi fi
else else
echo "PWRD isn't running..." echo "PWRD$mode isn't running..."
fi fi
} }
########################################################################
# MAIN
########################################################################
if [ ! -x "$JAVA" ]; then
echo "Please verify $JAVA is a valid java" 2>&1
exit 1
fi
case "$1" in case "$1" in
start) # Standalone start) # Standalone
pid_file=$base_dir/pwrd.pid pid_file=$BASE_DIR/pwrd.pid
start start
;; ;;
start-hub) # hub start-hub) # hub
pid_file=$base_dir/pwrd_hub.pid pid_file=$BASE_DIR/pwrd_hub.pid
start-hub start-hub
;; ;;
start-node) # node start-node) # node
pid_file=$base_dir/pwrd_node.pid pid_file=$BASE_DIR/pwrd_node.pid
start-node $2 start-node $2
;; ;;
stop) # standalone stop) # standalone
pid_file=$base_dir/pwrd.pid pid_file=$BASE_DIR/pwrd.pid
stop stop
;; ;;
stop-hub) # hub stop-hub) # hub
pid_file=$base_dir/pwrd_hub.pid pid_file=$BASE_DIR/pwrd_hub.pid
stop stop
;; ;;
stop-node) # node stop-node) # node
pid_file=$base_dir/pwrd_node.pid pid_file=$BASE_DIR/pwrd_node.pid
stop stop
;; ;;
restart) # standalone restart) # standalone
pid_file=$base_dir/pwrd.pid pid_file=$BASE_DIR/pwrd.pid
stop stop
start start
;; ;;
restart-hub) # hub restart-hub) # hub
pid_file=$base_dir/pwrd_hub.pid pid_file=$BASE_DIR/pwrd_hub.pid
stop stop
start-hub start-hub
;; ;;
restart-node) # node restart-node) # node
pid_file=$base_dir/pwrd_node.pid pid_file=$BASE_DIR/pwrd_node.pid
stop stop
start-node $2 start-node $2
;; ;;
status) status)
pid_file=$base_dir/pwrd.pid pid_file=$BASE_DIR/pwrd.pid
status status ""
;; pid_file=$BASE_DIR/pwrd_hub.pid
status-hub) # hub status " HUB"
pid_file=$base_dir/pwrd_hub.pid pid_file=$BASE_DIR/pwrd_node.pid
status status " Node"
;;
status-node) # node
pid_file=$base_dir/pwrd_node.pid
status
;; ;;
*) *)
echo "Usage: $SELF start*|stop*|restart*|status*" echo "Usage: $SELF start*|stop*|restart*|status"
echo " start* (standalone, hub or node)" echo " start* (standalone, hub or node)"
echo " start" echo " start"
echo " start-hub" echo " start-hub"
@ -314,12 +387,6 @@ case "$1" in
echo " restart" echo " restart"
echo " restart-hub" echo " restart-hub"
echo " restart-node http://hub:4444/grid/register" echo " restart-node http://hub:4444/grid/register"
echo " status* (standalone, hub or node)"
echo " status"
echo " status-hub"
echo " status-node"
exit 9 exit 9
;; ;;
esac esac
echo FIN [$1]