#!/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/$PS_PRODUCT_DIR/.gw.

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

SED=/usr/bin/sed

OSTYPE=`/bin/uname -s`
if [ "$OSTYPE" = "Linux" ]; then
  SED=/bin/sed
fi

#Go through the list of port info files

for j in `ls $1* | grep -v gw.pid`
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 instrance is not responding.
                /etc/init.d/gateway -n $conf_name start
            fi
        done
    fi
done
