#!/bin/bash -norc
#==============================================================
#
#  Abs:  Script to execute EPICS caRepeater
#
#  Name: st.caRepeater
#
#  Rem:  This Type II script is used to setup and start up EPICS caRepeater.
#        It should be run before any CA client.
#
#  Facility:  SLAC/LCLS
#
#  Auth: 14-Mar-2007, Jingchen Zhou      (jingchen)
#  Rev:  dd-mmm-yyyy, Reviewer's Name    (USERNAME)
#        
#        12-Nov-2007, Jingchen Zhou      (jingchen)
#        Converted to bash
#        Updated to support the standalone production environment
#        23-Jun-2009, Jingchen Zhou      (jingchen)
#        Support for multiple caRepeaters on Ebeam-Photon gateway host
#        08-Apr-1020, Jingchen Zhou      (jingchen)
#        Disabled the one listens to 5071, no longer in use.
#==============================================================

# make sure no other caRepeater runs
PIDS=`pgrep -x caRepeater`
if [ "$PIDS" != "" ]; then
    kill -9 "$PIDS"
fi

sleep 1

# set up environment for caRepeater (such as EPICS_CA_REPEATER_PORT)

if [ -f /nfs/slac/g/lcls/build/epics/setup/epicsReset.bash ]; then
    . /nfs/slac/g/lcls/build/epics/setup/epicsReset.bash
elif [ -f /usr/local/lcls/epics/setup/epicsReset.bash ]; then
    . /usr/local/lcls/epics/setup/epicsReset.bash
else
    echo "ERROR: this machine is not supported for LCLS dev/prod" 
    exit 1    
fi

cmdpath=`which caRepeater`
if [ ! -x "${cmdpath}" ]; then
        echo "ERROR: cannot find ${cmdpath}"
        exit 1
fi
# start caRepeater for port 5071 (for Gateway Request)
#export EPICS_CA_REPEATER_PORT=5071
#caRepeater > /dev/null &

# start caRepeater for port 5069 (for Gateway Serve)
export EPICS_CA_REPEATER_PORT=5069
caRepeater > /dev/null &

exit 0

# End of script
