From b2758e6738aa3249e103c75063302e58c9b3f893 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 4 Dec 2018 18:22:11 +0100 Subject: [PATCH] updates on pwrd, simplified --- pandora_server/util/pwrd/install_pwrd.sh | 39 ++-- pandora_server/util/pwrd/pwrd | 246 ++++++++++++++--------- 2 files changed, 183 insertions(+), 102 deletions(-) diff --git a/pandora_server/util/pwrd/install_pwrd.sh b/pandora_server/util/pwrd/install_pwrd.sh index 2de6b11e3d..0bae93c690 100644 --- a/pandora_server/util/pwrd/install_pwrd.sh +++ b/pandora_server/util/pwrd/install_pwrd.sh @@ -9,24 +9,33 @@ if [ "$1" == "" ] || [ "$1" != "--install" ]; then To install the Pandora web robot daemon (pwrd) Please launch this script as root: -$0 --install +$0 --install [directory] _HELP exit 0 fi -if [ "`rpm -qa | grep xorg-x11-server-Xvfb | wc -l`" == "0" ]; then - echo "Package xorg-x11-server-Xvfb is required" - exit 0 +if [ "`which rpm`" ]; then + if [ "`rpm -qa | grep xorg-x11-server-Xvfb | wc -l`" == "0" ]; then + echo "Package xorg-x11-server-Xvfb is required" + 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 chmod +x pwrd -PWR_SERVER_DEST=/usr/lib/pwr -PWR_SERVER_RSC=/etc/pwr/tmp -PWR_SERVER_LOG=/var/log/pwr -PWR_FIREFOX_INSTALLDIR=/opt +PWR_SERVER_DEST=$GLOBAL_INST_DIR/usr/lib/pwr +PWR_SERVER_RSC=$GLOBAL_INST_DIR/etc/pwr/tmp +PWR_SERVER_LOG=$GLOBAL_INST_DIR/var/log/pwr +PWR_FIREFOX_INSTALLDIR=$GLOBAL_INST_DIR/opt mkdir -p $PWR_SERVER_DEST mkdir -p $PWR_SERVER_LOG @@ -34,19 +43,22 @@ mkdir -p $PWR_SERVER_RSC 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/ tar xvzf firefox_profile.tar.gz >/dev/null chown -R `whoami`. firefox_profile 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 # Generate logrotate configuration - -cat > /etc/logrotate.d/pwrd < /etc/logrotate.d/pwrd /var/log/pwr/pwr_std.log +/var/log/pwr/xvfb.log /var/log/pwr/pwr_error.log { weekly missingok @@ -60,6 +72,10 @@ cat > /etc/logrotate.d/pwrd </dev/null 2>&1` @@ -37,45 +88,47 @@ function start_xvfb() { echo 1 fi 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 - ps -eo pid,cmd | grep Xvfb | grep -v grep | awk {'print $1 '} > $xvfb_pid_file echo 0 fi - } # 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 - if [ ! -e "$base_dir/pwrd_node.pid" ] && [ ! -e "$base_dir/pwrd.pid" ]; then - echo -n "Stopping Xvfb..." - PID=$(cat $xvfb_pid_file) - if [ `kill -9 $PID 2>&1 | grep "No such process" | wc -l` == "1" ]; 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..." + fi + 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 - 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 success fi return 0 fi 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 } -################################################################################ + +######################################################################## # START -################################################################################ +######################################################################## # Start Selenium Standalone server function start() { - if test -f $pid_file - then + if test -f $pid_file; then 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" exit 2 else @@ -91,11 +144,12 @@ function start() { return 1 fi - echo -n "Starting PWRD..." + if [ ! -e /etc/rc.d/init.d/functions ]; then + echo -n "Starting PWRD..." + fi 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 [ -e /etc/rc.d/init.d/functions ]; then success @@ -109,28 +163,29 @@ function start() { fi # 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 function start-hub() { - if test -f $pid_file - then + if test -f $pid_file; then 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" exit 2 else echo "Removing stale pid file: $pid_file" fi fi - echo -n "Starting PWRD..." + + if [ ! -e /etc/rc.d/init.d/functions ]; then + echo -n "Starting PWRD..." + fi # 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 [ -e /etc/rc.d/init.d/functions ]; then success @@ -144,15 +199,17 @@ function start-hub() { fi # 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 function start-node() { - if test -f $pid_file - then + if test -f $pid_file ; then 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" exit 2 else @@ -168,11 +225,12 @@ function start-node() { return 1 fi - echo -n "Starting PWRD..." + if [ ! -e /etc/rc.d/init.d/functions ]; then + echo -n "Starting PWRD..." + fi 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 [ -e /etc/rc.d/init.d/functions ]; then success @@ -186,32 +244,36 @@ function start-node() { fi # 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 Selenium Standalone server function stop() { if test -f $pid_file ; then echo -n "Stopping PWRD..." PID=$(cat $pid_file) - su $user -c "kill -3 $PID" - kill -9 $PID >/dev/null 2>&1 + [ "$PID" == "" ] && PID=`ps aux | grep "$JAVA -jar $PWR" | grep -v grep | awk '{print $2}'` + [ "$PID" != "" ] && su $USER -c "kill -3 $PID" + [ "$PID" != "" ] && kill -9 $PID >/dev/null 2>&1 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 success fi else echo "PWRD could not be stopped..." + [ "$PID" == "" ] && [ -f $pid_file ] && rm -f $pid_file if [ -e /etc/rc.d/init.d/functions ]; then failure + else + echo "Failed" fi - echo "Failed" fi stop_xvfb else @@ -224,84 +286,94 @@ function stop() { echo } -################################################################################ + +######################################################################## # STATUS -################################################################################ +######################################################################## # Status of Selenium Standalone server function status() { + mode=$1 if test -f $pid_file ; then + echo "checking: $pid_file" PID=`cat $pid_file` - if ps --pid $PID >/dev/null ; then - echo "PWRD is running: $PID" - if test -f $xvfb_pid_file ; then - PID=`cat $xvfb_pid_file` - if test -f $xvfb_pid_file ; then + if [ "$PID" != "" ] && ps --pid $PID >/dev/null ; then + echo "PWRD$mode is running: $PID" + if test -f $XVFB_PID_FILE ; then + PID=`cat $XVFB_PID_FILE` + if test -f $XVFB_PID_FILE ; then echo "Xvfb is running: $PID" fi fi else - echo "PWRD isn't running..." + echo "PWRD$mode isn't running..." fi else - echo "PWRD isn't running..." + echo "PWRD$mode isn't running..." fi } - + + + +######################################################################## +# MAIN +######################################################################## + +if [ ! -x "$JAVA" ]; then + echo "Please verify $JAVA is a valid java" 2>&1 + exit 1 +fi + case "$1" in start) # Standalone - pid_file=$base_dir/pwrd.pid + pid_file=$BASE_DIR/pwrd.pid start ;; start-hub) # hub - pid_file=$base_dir/pwrd_hub.pid + pid_file=$BASE_DIR/pwrd_hub.pid start-hub ;; start-node) # node - pid_file=$base_dir/pwrd_node.pid + pid_file=$BASE_DIR/pwrd_node.pid start-node $2 ;; stop) # standalone - pid_file=$base_dir/pwrd.pid + pid_file=$BASE_DIR/pwrd.pid stop ;; stop-hub) # hub - pid_file=$base_dir/pwrd_hub.pid + pid_file=$BASE_DIR/pwrd_hub.pid stop ;; stop-node) # node - pid_file=$base_dir/pwrd_node.pid + pid_file=$BASE_DIR/pwrd_node.pid stop ;; restart) # standalone - pid_file=$base_dir/pwrd.pid + pid_file=$BASE_DIR/pwrd.pid stop start ;; restart-hub) # hub - pid_file=$base_dir/pwrd_hub.pid + pid_file=$BASE_DIR/pwrd_hub.pid stop start-hub ;; restart-node) # node - pid_file=$base_dir/pwrd_node.pid + pid_file=$BASE_DIR/pwrd_node.pid stop start-node $2 ;; status) - pid_file=$base_dir/pwrd.pid - status - ;; - status-hub) # hub - pid_file=$base_dir/pwrd_hub.pid - status - ;; - status-node) # node - pid_file=$base_dir/pwrd_node.pid - status + pid_file=$BASE_DIR/pwrd.pid + status "" + pid_file=$BASE_DIR/pwrd_hub.pid + status " HUB" + pid_file=$BASE_DIR/pwrd_node.pid + status " Node" ;; *) - echo "Usage: $SELF start*|stop*|restart*|status*" + echo "Usage: $SELF start*|stop*|restart*|status" echo " start* (standalone, hub or node)" echo " start" echo " start-hub" @@ -314,12 +386,6 @@ case "$1" in echo " restart" echo " restart-hub" echo " restart-node http://hub:4444/grid/register" - echo " status* (standalone, hub or node)" - echo " status" - echo " status-hub" - echo " status-node" exit 9 ;; esac - -echo FIN [$1]