#!/bin/sh

ORBIT=/usr/local/etc/orbit
WEBLOGS=/usr/local/etc/copy-weblogs.pl
SECLOGS=/usr/local/etc/copy-seclogs.pl
GZIP=/usr/local/bin/gzip
MAILIF=/usr/minilocal/etc/mailifoutput
LOG=/var/log/cnet

# rotate the web server logs for the regular servers
if [ -f $LOG/httpd_access_log ]; then
    cd $LOG
    $ORBIT -U www -G www httpd_access_log 2
    $ORBIT -U www -G www httpd_error_log 2
    # send HUP before compression because compression takes a while
    if [ -f httpd.pid ]; then
	kill -HUP `/usr/bin/cat ./httpd.pid` 
    fi
    $GZIP httpd_access_log.1
    $GZIP httpd_error_log.1
    if [ -f httpd.archive ]; then
	if [ -x $WEBLOGS ]; then
	    # copy the log files and then remove them if copied ok
	    $MAILIF audit-cnet $WEBLOGS
	else
	    echo "$WEBLOGS not found"
	fi
    fi
    cd /var/log
fi

# rotate the web server logs for the secure servers
# different startup script for each server type: xxx, www1, wwwc
# because we have to get a different password for each server
for CMD in "/etc/init.d/httpsd-*"; do
  if [ -f $LOG/httpsd_access_log ]; then
    cd $LOG
    $ORBIT -U www -G www httpsd_access_log 2
    $ORBIT -U www -G www httpsd_error_log 2
    $ORBIT -U www -G www httpsd_misc_log 2

    # can't do it by HUP; have to stop and start them
    $CMD stop terse
    $CMD start terse 

    $GZIP httpsd_access_log.1
    $GZIP httpsd_error_log.1
    $GZIP httpsd_misc_log.1
    if [ -f httpsd.archive ]; then
	if [ -x $SECLOGS ]; then
	    # copy the log files and then remove them if copied ok
	    $MAILIF audit-cnet $SECLOGS
	else
	    echo "$SECLOGS not found"
	fi
    fi
    cd /var/log
  fi
done
