#!/bin/bash

set -x
# environment variable
# APP_NAME, eg: loganwy-xx-xx.jar
# JAVA_OPT, eg: -Xms -Xmx -Xmn -Dxxx=x

# set default env
if [[ -z "${APP_PATH}" ]]; then
  APP_PATH="/opt"
fi

if [[ -z "${LOG_PATH}" ]]; then
  LOG_PATH="/var/log"
fi

# set default jvm
if [[ -z "${JAVA_OPT}" ]]; then
  JAVA_OPT="-server -Xmn1280m -Xms2560m -Xmx2560m -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=70 -XX:MaxDirectMemorySize=512m -XX:+UseCMSInitiatingOccupancyOnly -XX:SurvivorRatio=8 -XX:+ExplicitGCInvokesConcurrent -XX:MetaspaceSize=512m -XX:MaxMetaspaceSize=512m"
fi

# agent: /opt/pinpoint/agent/pinpoint-bootstrap-1.8.5.jar
#JAVA_OPT="-Dpinpoint.applicationName=$PINPOINT_APPLICATION_NAME $JAVA_OPT"
#JAVA_OPT="-Dpinpoint.agentId=$PINPOINT_AGENT_ID_PREFIX`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"` $JAVA_OPT"
# JAVA_OPT="-Dpinpoint.agentId=$PINPOINT_AGENT_ID $JAVA_OPT"
#JAVA_OPT="-javaagent:/opt/pinpoint/agent/pinpoint-bootstrap-1.8.5.jar $JAVA_OPT"

echo "JAVA OPERATIONS: $JAVA_OPT"
echo "${APP_PATH}/${APP_NAME} is starting, you can check the ${LOG_PATH}/nohup.out"
echo "java ${APP_PATH}/${APP_NAME}" >${LOG_PATH}/nohup.out 2>&1 &
#java ${JAVA_OPT} -jar ${APP_PATH}/${APP_NAME} >${LOG_PATH}/nohup.out 2>&1 &
java -jar ${APP_PATH}/${APP_NAME} >${LOG_PATH}/nohup.out 2>&1 &

tail -f ${LOG_PATH}/nohup.out