Commit bd6cc6ba authored by Kirk Webb's avatar Kirk Webb

Made a couple of simple fixes to apachelogroll.

1) The timeout counter was not initialized
2) The script does not attempt to run apachectl if apache isn't running

Also took the opportunity to clean up a bit, and add comments.
parent c19c4236
#! /bin/sh
# CONSTANTS INIT
PIDFILE=/var/run/apache.pid
LOGDIR=/usr/testbed/log
DESTDIR=/z/testbed/logs/apache
APACHECTL=/usr/local/sbin/apachectl
LOGS='apache_access_log apache_error_log apache_ssl_engine_log
apache_ssl_request_log'
LOGS='apache_access_log apache_error_log apache_ssl_engine_log apache_ssl_request_log'
SIZELIMIT=5000 # about 5 MB
DATE=`date '+%Y-%m-%d'`
MOVED=0
MAXTRIES=10
# GLOBAL VARIABLES INIT
MOVED=0
cd $LOGDIR
#
# CHECK THE LOG FILES
#
# For each apache log, check its size to see if it has exceeded the size
# limit above. If so, move it to a temp filename for archival
#
for CURLOG in $LOGS
do
if [ -f $CURLOG -a ! -e ${CURLOG}.${DATE} ]
......@@ -21,35 +29,58 @@ do
if [ $LOGSIZE -gt $SIZELIMIT ]
then
mv $CURLOG ${CURLOG}.${DATE}
echo "Rolling $CURLOG at $LOGSIZE kbytes"
MOVED=1
fi
fi
done
#
# ARCHIVE THE LOG FILES
#
# OK, if any files have been moved, they need to be archived. First, we need
# to restart apache so that it will reopen its log files under their original
# names (rather than using the moved ones, which it still has open initially).
# Don't try to archive the open, moved log files until apache closes them.
#
# Don't restart apache if it isn't running. Do always archive the logs if
# necessary though.
#
if [ $MOVED -eq 1 ]
then
$APACHECTL graceful
if [ $? -ne 0 ]
# Should be a proc entry if the process is running!
# Note that a graceful restart waits for all clients to disconnect.
if [ -e /proc/`cat $PIDFILE` ]
then
echo "Apache restart failed"
exit 1
$APACHECTL graceful
if [ $? -ne 0 ]
then
echo "Apache restart failed"
exit 1
fi
fi
# wait a bit for apache to restart
sleep 60
# Now, lets try to archive off those logs..
for CURLOG in `ls *.${DATE}`
do
# This while loop makes sure nothing still has the moved logfile open.
COUNT=$MAXTRIES
while fstat $CURLOG | grep -q -v "USER"
do
sleep 60
COUNT=`expr $COUNT + 1`
if [ $COUNT -gt $MAXTRIES ]
if [ $COUNT -eq 0 ]
then
echo "Tired of waiting for file to become free"
exit 1
fi
COUNT=$(($COUNT-1))
done
# deflate, and move (safely).
gzip -9 $CURLOG && cp $CURLOG.gz $DESTDIR && rm $CURLOG.gz
if [ $? -ne 0 ]
then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment