#!/bin/bash

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

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

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

HEAP_MEMORY=512m
SERVER_JAR=`ls ../lib/adscounter-temp-scheduler-1.18.4.jar`

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