#
# PROPRIETARY/CONFIDENTIAL. Use of this product is subject to
# license terms. Copyright C 2001-2003 Sun Microsystems, Inc.
# All rights reserved.
#

tailor="NO"
for option in $@
do
  if [ "$option" = "-t" ]
  then
    tailor="YES"
  fi
done

if "${ROOT_INSTANCE}/status-dps" > /dev/null 2>&1 ; then
    pid=`${DPS_CAT} "${PID_FILE}"`
    ${DPS_ECHO} "DPS on ${INSTANCE} is already running ($pid)."
    exit 1
fi

${DPS_ECHO} "Starting DPS on ${INSTANCE}"

if ${DPS_TEST} -f "${PORT_FILE}" ; then
   ${DPS_RM} ${PORT_FILE}
fi

if [ "$tailor" = "NO" ]
then
  cd "${ROOT}/bin/dps/server/bin"; ./ldapfwd -t "${ROOT_INSTANCE}/etc/tailor.txt" $@
else
  cd "${ROOT}/bin/dps/server/bin"; ./ldapfwd $@
fi

counter=5

while ${DPS_TEST} 0 -lt $counter ; do
    if ${DPS_TEST} -f "${PID_FILE}" ; then
       counter=0
    else
       counter=`${DPS_EXPR} $counter - 1`
       ${DPS_SLEEP} 1
    fi
done

if "${ROOT_INSTANCE}/status-dps" ; then
   exit 0
fi

exit 1
