#!/bin/bash

# fclogrotate
#
# $Id: fclogrotate 1351 2010-08-12 17:51:24Z jhealy $
#
# This script takes the existing FC InetSvcs log file, moves it
# to an archive directory, and compresses it.  This script should
# be called just BEFORE InetSvcs starts; you may use the hooks
# provided in the FC startup scripts to do this.
#
# This script is non-destructive; it does not move or delete any
# files (we rely on fc to roll the log file for us).
#

# compressor to use on log file
COMPRESSOR="nice -n 20 /bin/bzip2"

# original log file
LOGFILE="$SERVICE_FOLDER/$SERVICE_APP.log"

# directory to store archived logs
ARCHIVES="/var/log/$SERVICE_APP"


####
#### Don't edit below this mark unless you know what you're doing
####

# get current date and time to name the log file
DATE=`/bin/date +%Y-%m-%d.%H-%M-%S`

# compute the destination log name
DESTLOG="${ARCHIVES}/$SERVICE_APP.log.${DATE}"


if [ -f "${LOGFILE}" ]; then
    echo "fclogrotate: Saving copy of logfile with date ${DATE}"
    cp "${LOGFILE}" "${DESTLOG}"
    
    echo "fclogrotate: Compressing logfile in the background"
    ${COMPRESSOR} "${DESTLOG}" &
else
    echo "fclogrotate: No logfile (${LOGFILE}) to save at ${DATE}; skipping"
fi

