#!/bin/ksh
# $Id: rotate-httpd,v 1.1 1996/06/27 11:41:13 stefan Exp $
#
# Rotate server log files and archive the old logfiles.
# Does not affect users who may be connected to the server.
#
# Copyright 1996 by Stefan Stapelberg, <stefan@rent-a-guru.de>
#
# $Log: rotate-httpd,v $
# Revision 1.1  1996/06/27  11:41:13  stefan
# Initial revision
#
#

# SRVROOT is the name of the ServerRoot directory.
SRVROOT=/usr/ns-home

# CFGFILE defines the name of the config file for this server.
CFGFILE=analyze.conf

# ANALYZE contains the name of the executable program.
ANALYZE=/usr/local/bin/http-analyze

# SRVLIST contains the names of all SERVER_ROOT configuration directories
SRVLIST='httpd-80'

# Add here any additional logfiles you want rotated.
LOGS='access errors secure'

typeset -i MON YEAR
typeset -Z2 MON

eval $(date "+MABB='%B' MON='%m' YEAR='%Y'")

((MON=$MON-1)); [ $MON -eq 0 ] && { MON="12"; ((YEAR=$YEAR-1)); }
LOGDIR="log$YEAR"

cd $SRVROOT || { echo "panic: can't cd into $SRVROOT" 1>&2; exit 1; }

for server in $SRVLIST; do
	(cd $server/logs
	    [ ! -d "$LOGDIR" ] && { mkdir $LOGDIR; }
	    for file in $LOGS; do
		[ -f $file ] && { mv $file $LOGDIR/$file.$MON; }
		echo "$server/logs/$file saved in $LOGDIR/$file.$MON" 1>&2
	    done)
	$server/restart
done

# Now run http-analyze for each server. For each server,
# a configuration file must exist under the ServerRoot.
for server in $SRVLIST; do
	test -s $CFGFILE && \
	  { $ANALYZE -m -c $CFGFILE $LOGDIR/$file.$MON; \
	    $ANALYZE -m -c $CFGFILE; }
done
