#!/bin/sh
#
# This is the JOB Server startup script.
#
# You only need to set up the JOB Server on this machine if you want
# to gain access to ODBC databases on this machine through the Easysoft
# JDBC-ODBC Bridge Driver. 
#
# The JOB Server is dynamically linked with libodbc.<shared_extension>
#
# <shared_extension> is .so, .a or .sl depending on your platform.
#
ldpaths=`cat  /usr/local/easysoft/etc/es.ld.so.conf `
ldpaths=`echo  $ldpaths | sed 's/ /:/g'`
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ldpaths
export LD_LIBRARY_PATH
SHLIB_PATH=$SHLIB_PATH:$ldpaths
export SHLIB_PATH
LIBPATH=$LIBPATH:$ldpaths
export LIBPATH

cat <<EOF 
Attempt to stop the JOB Server

EOF
./stopjob

if [ -r LOG ];then
  if [ ! -w LOG ];then
  cat <<EOF
The log file `pwd`/LOG
is not writeable by the current user. Please start JOB as another user, the
root user, or change the permissions on 
`pwd`/LOG.

JOB Server is not started.

EOF
  exit 1
  fi
else
  if [ ! -w . ];then
    cat <<EOF
Cannot create LOG file in `pwd`

EOF
    exit 1
  fi
  touch LOG
  if [ $? != 0 ];then
    echo "Failed to create LOG file in `pwd`"
    exit 1
  fi
fi
cat <<EOF > LOG
Easysoft JDBC-ODBC Bridge Server diagnostic log file
`date`
EOF
if  [ -r LOG ];then
  ### No Log file create it if the server startup fails then remove it

  cat <<EOF 
A LOG file exists.

JOB server will start in the background
the diagnostic output of the server can be seen using the command:

tail -f `pwd`/LOG


use  `pwd`/stopjob 

to stop the JOB server.

use  `pwd`/startjob 

to (re)start the JOB server

Point your browser to:

http://`hostname`:8031/

To see the JOB Server Web Pages


EOF
  (cd /usr/local/easysoft/job/server; ./esjobserver standalone  2>> ../LOG 1>>../LOG) &
else
  cat <<EOF

Failed to create `pwd`/LOG logfile

JOB Server is not started.



EOF
  exit 1
fi






