#!/bin/sh

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

. ./setenv.sh

APP_HOME=.
CLASSPATH=$APP_HOME:$APP_HOME/lib/ext/bgcommon-boot.jar
COMMON_PARAMS="-Dnetworkaddress.cache.ttl=3600 -Djava.net.preferIPv4Stack=true -Dboot.info=1 -Dapp.name=BGTvAccounting -Djava.endorsed.dirs=${APP_HOME}/lib/endorsed:${JAVA_HOME}/lib/endorsed"
LOG_PARAMS="-Dlog.dir.path=log/ -Dlog4j.configuration=log4j-accounting.xml"
NAME=tv-accounting
NAME_SHORT=accounting
ADMIN_PORT=1982
MEMORY=-Xmx256m

if [ "$1" = "start" ]; then
	nohup  ${JAVA_HOME}/bin/java ${COMMON_PARAMS} ${LOG_PARAMS} ${MEMORY} -Dadmin.port=$ADMIN_PORT -cp ${CLASSPATH} ru.bitel.common.bootstrap.Boot ru.bitel.bgbilling.kernel.application.server.Application ${NAME} > ./log/${NAME_SHORT}.out 2>&1 & echo $! > .run/${NAME_SHORT}.pid &
else
	if [ "$1" = "debug" ]; then
		#starting in debug mode
	    nohup  ${JAVA_HOME}/bin/java ${COMMON_PARAMS} ${MEMORY} -Dadmin.port=$ADMIN_PORT -cp ${CLASSPATH} -enableassertions -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=5589,server=y,suspend=n ru.bitel.common.bootstrap.Boot ru.bitel.bgbilling.kernel.application.server.Application ${NAME} > ./log/${NAME_SHORT}.out 2>&1 & echo $! > .run/${NAME_SHORT}.pid
	else
		#execute command
		${JAVA_HOME}/bin/java ${COMMON_PARAMS} -Dadmin.port=$ADMIN_PORT -cp ${CLASSPATH} ru.bitel.common.bootstrap.Boot ru.bitel.bgbilling.kernel.application.server.Application ${NAME} "$@"
	fi
fi
