#!/bin/sh
# This script if used by cron job to test whether all instances of gateway are up and
# running.
# Expects the base filename usually - $PS_VAR_DIR/.rp.

###############################################
# Sourcing macros
###############################################
DIRNAME=/usr/bin/dirname
. `$DIRNAME $0`/../lib/psmacros

#Go through the list of port info files

for j in $1*
do
    if [ -r $j ]
    then
        port=`cat $j`
        conf_name=`echo $j | $SED -e "s#$1##"`
        
        for i in $port
        do
            ${BASE_DIR}/$PS_PRODUCT_DIR/bin/checkport GATEWAY_IPADDR $i $2
            if [ $? -eq 1 ]  
            then
                # At least one port of this instance is not responding.
                /etc/init.d/rwproxyd -n $conf_name start
            fi
        done
    fi
done
