#!/bin/bash

# This sets up environment variables and starts up the V4 archiver appliance service.

if [ $# -ne 2 ]; then
    echo "Usage: $0 DEV|PROD|TESTFAC start|stop"
    exit 1
fi
FACILITY=`echo $1 | tr '[:lower:]' '[:upper:]'`

# Remove the facility argument from the list if arguments
shift 1

[ -z "$PACKAGE_TOP" ] && export PACKAGE_TOP="/afs/slac/g/lcls/package"

if [[ `arch` == "x86_64" ]]
then
  ARCH="linux-x86_64"
else
  ARCH="linux-x86"
fi

HOSTNAME=`hostname`

export JAVA_HOME=${PACKAGE_TOP}/java/jdk1.8.0_60/${ARCH}
export COMMONS_DAEMON_FOLDER=${PACKAGE_TOP}/commons-daemon/1.0.15/linux-x86


case $FACILITY in
DEV)
    # Put the logs in $PHYSICS_DATA
    export LOGS_FOLDER=/nfs/slac/g/lcls/physics/log
    cd /afs/slac/g/lcls/physics/archapplv4proxy/
    ./startV4archapp.sh hist http://lcls-archapp.slac.stanford.edu/retrieval/ $@
    ;;
PROD)
    # Put the logs in $PHYSICS_DATA
    export LOGS_FOLDER=/nfs/slac/g/lcls/physics/log
    cd /mccfs2/usr/local/lcls/physics/archapplv4proxy/
    ./startV4archapp.sh hist http://lcls-archapp.slac.stanford.edu/retrieval/ $@
    ;;
TESTFAC)
    # Put the logs in $PHYSICS_DATA
    export LOGS_FOLDER=/nfs/slac/g/acctest/physics
    cd /afs/slac/g/acctest/physics/archapplv4proxy/
    ./startV4archapp.sh hist http://testfac-archapp.slac.stanford.edu/retrieval/ $@
    ;;
*)
    echo "FACILITY $FACILITY not supported"
    exit 1
    ;;
esac

