#!/bin/bash


#
# starts UVOS WS server
#


source /usr/share/unicore/uvos-server/script/_setenv.sh
#OPTS=$OPTS" -Xdebug -Xrunjdwp:transport=dt_socket,address=6009,server=y,suspend=n"

#
# check whether the server might be already running
#

DEFAULT_UVOS_SERVER_CONFIG="/etc/unicore/uvos-server/uvosServer.conf"

if [ -z "$UVOS_SERVER_CONFIG" ]
then
        UVOS_SERVER_CONFIG=$DEFAULT_UVOS_SERVER_CONFIG
fi




LOGDIR="/var/log/unicore/uvos-server/"
PIDDIR="/var/run/unicore/"
PID=${PIDDIR}"uvos-server.pid"
LOG=${LOGDIR}"startup.log"

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

PARAM=$UVOS_SERVER_CONFIG
export CLASSPATH=$CP

nohup $JAVA ${MEM} ${OPTS} ${DEFS} pl.edu.icm.unicore.uvos.server.VOServer ${PARAM} >& $LOG & 
echo $! > $PID
