#!/bin/sh

# determine location
# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ]; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

# Get standard environment variables
PRGDIR=`dirname "$PRG"`

JAVA=`which java`
SERVER_HOME=${PRGDIR}/server
SERVER_LOG=$SERVER_HOME/standalone/log

[ -n "$JAVA" ] || { echo "No Java Runtime Environment found" && exit 1; }

cd ${PRGDIR}

echo "Start db .."
nohup $JAVA -cp $SERVER_HOME/modules/com/h2database/h2/main/h2-1.3.161.jar org.h2.tools.Server -baseDir ./data > $SERVER_LOG/h2.out &
echo "  The databse is now starting, check output in $SERVER_LOG/h2.out"
echo " "

sleep 3

echo "Start Flarmradar Server .."
nohup /bin/sh $SERVER_HOME/bin/standalone.sh > /dev/null &
echo "  The server is now starting, check output in $SERVER_LOG/server.log"
echo " "