# shell to start the proxy services
#
# will also rotate the log files in the given directory
# date is in the form YYMMDDHHMMSS

LOG_DIRECT=`pwd`
LOG_FILE="proxy.output"
CONFIG_FILE="proxy.config"
DATE=`date '+%y%m%d%H%M%S'`

JAVA_ARGS="-ms256m -mx256m -noclassgc -noverify -verbosegc "

ulimit -s 256000 -n 2000

# rotate the logs
if [ -f $LOG_DIRECT/$LOG_FILE ]
then

        /bin/cp $LOG_DIRECT/$LOG_FILE $LOG_DIRECT/$LOG_FILE.$DATE
        /bin/cp /dev/null $LOG_DIRECT/$LOG_FILE

else

        echo "$LOG_DIRECT/$LOG_FILE does not exist, will create ..."
        touch $LOG_DIRECT/$LOG_FILE

fi


# log in messages file the restart
logger -p daemon.info "Proxy server started on $DATE in $LOG_DIRECT/$LOG_FILE."

# start the proxy if the config file exists
if [ -f $LOG_DIRECT/$CONFIG_FILE ]
then

        echo "Starting the proxy server"
        echo    
        # start the java process for testing
        #/usr/bin/java ProxyServer
        # start the java process for production
        #nohup /usr/bin/java $JAVA_ARGS ProxyServer &
        nohup java $JAVA_ARGS ProxyServer &

        # echo process id to store file
        echo "$!" > pidfile

else

        echo "Config file does not exist!  Proxy is not starting..."
        logger -p daemon.info "Error starting proxy server on $DATE"

fi
