#!/bin/bash

ACTIVE="$1"
if [ -z "$ACTIVE" ]; then
  ACTIVE="production"
  echo "Use default profile: $ACTIVE"
fi
HEAP="$2"
if [ -z "$HEAP" ]; then
  HEAP="6g"
  echo "Use default heap: $HEAP"
fi

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

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

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

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