#!/bin/sh
#
#Startup script for the XUUDB server
#

#
#Java command 
#
JAVA=java

#
# PID file
#
PID=/var/run/unicore/xuudb.pid

#
# Startup log
#
STARTLOG=/var/log/unicore/xuudb/startup.log

cd /etc/unicore/xuudb

#
#Memory for the VM
#
MEM=-Xmx128m

#
#Options
#
#log config file
OPTS=$OPTS" -Dlog4j.configuration=file:///etc/unicore/xuudb/logging.properties"
OPTS=$OPTS" -Djava.util.logging.config.file=/etc/unicore/xuudb/logging.properties"

#set this one if you have ssl problems and need debug info
#OPTS=$OPTS" -Djavax.net.debug=ssl,handshake"

#
#put all jars in lib/ on the classpath
#
JARS=/usr/share/unicore/xuudb/lib/*.jar
CP=.
for JAR in $JARS ; do 
    CP=$CP:$JAR
done


PARAM=$*
if [ "$PARAM" = "" ]
then
  PARAM="--start /etc/unicore/xuudb/xuudb_server.conf"
fi


#
# check whether the server might be already running
#
if [ -e $PID ] 
 then 
  if [ -d /proc/$(cat $PID) ]
   then
     echo "An XUUDB server instance may be already running with process id "$(cat $PID)
     echo "If this is not the case, delete the file $INST/$PID and re-run this script"
     exit 1
   fi
fi


#
#go
#
nohup $JAVA ${MEM} ${OPTS} ${DEFS} -cp ${CP} de.fzj.unicore.xuudb.server.XUUDBServer ${PARAM}  > "$STARTLOG" 2>&1  & echo $! > "$PID"



