#!/bin/bash

ACTIVE="$1"
if [ -z "$ACTIVE" ]; then
  ACTIVE="production"
  echo "Use default profile: $ACTIVE"
fi

[ ! -d ~/run/ ] && mkdir -p ~/run

if [ -f ~/run/pangu-rta-api.pid ]; then
  echo "Server [pangu-rta-api] pid file has been exists!";
  exit
fi

SERVER_JAR=`ls ../lib/pangu-rta-api-1.2.0.jar`

exec "${JAVA_HOME}/bin/java" -server -Dspring.profiles.active=$ACTIVE -Xms1g -Xmx1g -XX:+HeapDumpOnOutOfMemoryError -XX:+UseG1GC -jar ${SERVER_JAR} >/dev/null 2>&1 & echo $! > ~/run/pangu-rta-api.pid