#!/bin/bash

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

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

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

HEAP_MEMORY=1g
SERVER_JAR=`ls ../lib/shopping-web-1.6.2.jar`


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