#!/bin/bash

. bin/config

if [ -e $PID_FILE ]; then

	echo
	echo "        ERROR: server already running."
	echo
	echo "        Please stop any running instances before starting a"
	echo "        new one. (Remove $PID_FILE if this message appears"
	echo "        even if no server is running.)"
	echo

	exit 0

fi

echo

if [ ! -e "logs" ]; then

	echo "        Creating logs directory..."

	mkdir logs

fi


if [ ! -e "structr" ]; then

	echo "        Unarchiving static resources..."

        jar -xf $(find . -maxdepth 1 -name "*.jar" ! -name "*-sources.jar" ! -name "*-javadoc.jar"|sort|head -n 1) structr

fi

echo -n "        Starting structr server $DISPLAY_NAME: "

java $RUN_OPTS $JAVA_OPTS $MAIN_CLASS >$LOG_FILE 2>&1 & echo $! >$PID_FILE

sleep 1

echo "OK"
echo
