#!/bin/sh
#
# Copyright (c) 2002 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

# Rotates server log files
# This can be run as a cron script

LANG=C ; export LANG
LC_ALL=C ; export LC_ALL

. %%%INSTALL_CONFIG_ROOT%%%/asenv.conf

SERVER_ROOT=${AS_INSTALL_ROOT}

PRODUCT_SUBDIR=%%%SUBDIR%%%
DATE=`date +%d%h-%I%M%p`

LD_LIBRARY_PATH=%%%LD_LIBRARY_PATH%%%

cd %%%ROOT%%%/lib

# get the error log file information by parsing the server.xml
ERRORLOGS=`./parsexml ${PRODUCT_SUBDIR}/config log-service file`

# get the access log file information by parsing the server.xml
ACCESSLOGS=`grep accesslog ${PRODUCT_SUBDIR}/config/server.xml \
              | sed -e 's/.* value="\([^"]*\)".*/\1/g'`

# Now that we have the necessary information rotate the log files
# and restart the server instance

(cd ${PRODUCT_SUBDIR}/logs;

 for i in $ERRORLOGS; do
   if [ -f $i ]; then
     mv $i $i.$DATE
   fi
 done

 for i in $ACCESSLOGS; do
   if [ -f $i ]; then
     mv $i $i.$DATE
   fi
 done

 if [ -f pid ]; then
   ${PRODUCT_SUBDIR}/bin/restartserv
 fi
)
