#!/bin/sh

java="${NICOCACHE_JAVA:-java}"
opts="${NICOCACHE_OPTS:--Xmx128m}"

if [ "$1" = "debug" ]; then
  opts="$opts -Ddareka.debug=true -Ddareka.logfile=debug.log -ea"
elif [ $# != 0 ]; then
  opts="$*"
fi

cd `dirname $0`

while :
do
  $java $opts -jar `basename $0 .sh`.jar
  case $? in
  25) echo "waiting 5 seconds for restarting..."
     sleep 5
     continue;;
  *) echo "exit status is $?"
     break;;
  esac
done

exit 0
