updates on pwrd, simplified

This commit is contained in:
fbsanchez 2018-12-04 18:22:11 +01:00
parent 4fa3f967f6
commit b2758e6738
2 changed files with 183 additions and 102 deletions

View File

@ -9,24 +9,33 @@ 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 [directory]
_HELP _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
if [ "$2" != "" ] && [ -d "$2" ]; then
GLOBAL_INST_DIR=$2
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 mkdir -p $PWR_SERVER_DEST
mkdir -p $PWR_SERVER_LOG mkdir -p $PWR_SERVER_LOG
@ -34,19 +43,22 @@ mkdir -p $PWR_SERVER_RSC
mkdir -p $PWR_FIREFOX_INSTALLDIR mkdir -p $PWR_FIREFOX_INSTALLDIR
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/
tar xvzf firefox_profile.tar.gz >/dev/null tar xvzf firefox_profile.tar.gz >/dev/null
chown -R `whoami`. firefox_profile chown -R `whoami`. firefox_profile
mv firefox_profile $PWR_FIREFOX_INSTALLDIR mv firefox_profile $PWR_FIREFOX_INSTALLDIR
mkdir -P $PWR_FIREFOX_INSTALLDIR/selenium
mv config.json $PWR_FIREFOX_INSTALLDIR/selenium/
ln -s $PWR_FIREFOX_INSTALLDIR/firefox/firefox /usr/bin/firefox ln -s $PWR_FIREFOX_INSTALLDIR/firefox/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,6 +72,10 @@ cat > /etc/logrotate.d/pwrd <<EO_LROTATE
EO_LROTATE EO_LROTATE
# Update pwrd daemon
if [ "$GLOBAL_INST_DIR" != "" ]; then
sed -i "s/PWR_GLOBAL_DIR=\"\"/PWR_GLOBAL_DIR=\"\\$GLOBAL_INST_DIR\"/g" ./pwrd
fi
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
chmod +x /etc/init.d/pwrd chmod +x /etc/init.d/pwrd
@ -77,4 +93,3 @@ Please start the service with:
EOF EOF

View File

@ -1,9 +1,26 @@
#!/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 # pidfile: $BASE_DIR/pwr.pid
# Source function library. # Source function library.
@ -12,21 +29,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 +88,47 @@ 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 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 "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,33 +244,37 @@ 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" != "" ] && su $USER -c "kill -3 $PID"
[ "$PID" != "" ] && 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 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
else else
echo "PWRD could not be stopped..." echo "PWRD could not be stopped..."
[ "$PID" == "" ] && [ -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
failure failure
fi else
echo "Failed" echo "Failed"
fi fi
fi
stop_xvfb stop_xvfb
else else
echo "PWRD is not running." echo "PWRD is not running."
@ -224,84 +286,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 +386,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]