#!/bin/sh

cd ${0%${0##*/}}.

if [ -z "$JAVA_HOME" ]; then
  echo "The JAVA_HOME environment variable is not defined"
  echo "This environment variable is needed to run this program"
  exit 1
fi

BGBILLING_SERVER_DIR=.
CLASSPATH=${BGBILLING_SERVER_DIR}:${BGBILLING_SERVER_DIR}/lib/*

if [ "$1" = "-estart" ]; then
	#starting
	nohup  nice -5 ${JAVA_HOME}/bin/java -Djava.net.preferIPv4Stack=true -Dapp.name=BGDataLoader -Dnetworkaddress.cache.ttl=3600 -Xmx256m -cp ${CLASSPATH} ru.bitel.common.bootstrap.Boot bitel.billing.server.DataLoader $1 $2 $3 > ./log/dataloader.out 2>&1 & echo $! > .run/bgdataloader.pid &
else
	if [ "$1" = "debug" ]; then
		#starting in debug mode
		nohup  nice -5 ${JAVA_HOME}/bin/java -Djava.net.preferIPv4Stack=true -enableassertions -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=5589,server=y,suspend=n -Dapp.name=BGDataLoader -Dnetworkaddress.cache.ttl=3600 -Xmx256m -cp ${CLASSPATH} ru.bitel.common.bootstrap.Boot bitel.billing.server.DataLoader -estart $2 $3 > ./log/dataloader.out 2>&1 & echo $! > .run/bgdataloader.pid &
	else
		#execute command
		${JAVA_HOME}/bin/java -Djava.net.preferIPv4Stack=true -Dnetworkaddress.cache.ttl=3600 -Xmx256m -cp ${CLASSPATH} bitel.billing.server.DataLoader $1 $2 $3
	fi
fi

