You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by De...@McKGenMed.com on 2002/08/23 15:36:41 UTC

failure notice


Do you need to stop the apache process to rotate logs?  Some documentation
I read indicated you had to and some didn't.  I did find this script on the
Sun site.  It just appears to copy and compress the logs and then performs
a touch to 0 it out.  Any thoughts or experience with this?

###########################################################################
#!/usr/bin/bash

###
# rotate_apache
#
# Rotate apache server logs.
# Finds the 'access_log' and 'error_log' in
# the apache directory and duplicates and
# compresses them.
#
# Can be run as a cron job
#
# Submitted by: Robert Banniza robert@rootprompt.net

### Vars used throughout - adjust as needed
DATE=`date +%d%h-1.1p`
#HOMEDIR='/users/u1'
HOMEDIR='/usr/local'
LOGS='access_log
error_log'


# main.

for h in $(ls $HOMEDIR);
do
             for i in $LOGS;
             do
                         if [ -f $HOMEDIR/$h/logs/$i ]; then
                                     cp $HOMEDIR/$h/logs/$i
$HOMEDIR/$h/logs/$i.$DATE
                                     touch $HOMEDIR/$h/logs/$i
                                     gzip $HOMEDIR/$h/logs/$i.$DATE
                         fi

                         # search and destroy.
                         find $HOMEDIR/$h/logs -name $i.* -a -mtime +30
-exec rm {} \;

             done
done






---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: failure notice

Posted by Jacob Coby <jc...@listingbook.com>.
> Do you need to stop the apache process to rotate logs?  Some documentation
> I read indicated you had to and some didn't.  I did find this script on
the
> Sun site.  It just appears to copy and compress the logs and then performs
> a touch to 0 it out.  Any thoughts or experience with this?

You'll need to do a killall -SIGHUP after you've rotated the logs, else
apache won't be able to write to the new log.

I use logrotate, much simpler to debug :).

-- /etc/logrotate.d/httpd --
# rotate apache logs
#size=25M
/usr/local/apache/logs/*_log /usr/local/apache/logs/listingbook.com/*_log {
        daily
        rotate 5
        create 644
        missingok

        postrotate
                /usr/bin/killall -HUP /usr/local/apache/bin/httpd
        endscript
}
-- end --

-Jacob
http://www.listingbook.com


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: failure notice

Posted by Dirk-Willem van Gulik <di...@webweaving.org>.
A 'graceful' restart (-HUP) is fine under most circumstances (though there
are few exceptions; such as when you have a password on an SSL
certificate). Typical method:

	mv access_log ac.lastday.old

	# kill -HUP <pid>
	apachectl restart

	sleep 900

	cat ac.lastday.old |\
		 gzip -c > /archive/access_log.`date +%Y%m%d`.log.gz

	rm -f ac.lastday.old

Note two things; the 'mv' happens on the same file system; so apache is
unaware of it and will continue to write to the file now called
'ac.lastday.old'. But yet we move it 'aside' so that apache can
start a new access_log.

After the restart we wait 15 minutes. This is so that all children can
finish what they are doing properly.

Only then do we archive to what is possibly another disk/mount.

Note that after the RM, if there are still lingering children; that you
starts to loose logs, or on an NFS partition, you get those pescky
#123 cruft.

Dw


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org