Re: rotatate logs - Apache has anyone got this to rotate at a specific time?

  • From: Chuck Edwards <chuck@xxxxxxxxxxxxx>
  • To: ora-apps-dba@xxxxxxxxxxxxx
  • Date: Fri, 16 Oct 2009 08:37:36 -0700

Have you tries using logrotated? It's included in most Linux distros, but available for any UNIX. Don't know about Windows. You can easily set it up to run out of cron and do a graceful apache HUP:


Here's a logrotate script I use - this is in /etc/logrotate.d, but you can run logrotate directly from a cron script at midnight, too:

<path to ias_oracle_home>/Apache/Apache/logs/error_log <path to ias_oracle_home>/Apache/Apache/logs/error_log_pls <path to ias_oracle_home>/Apache/Jserv/logs/mod_jserv.log {
   copytruncate
   compress
   size=1M
   rotate 9
   postrotate
su - applprod -c "/opt/oracle/prodcomn/admin/scripts/ prod_diana/adapcctl.sh status" if [ $? -ne 1 ]; then # Status of 1 indicates apache is already down and
                                # there is no need to HUP the process
su - applprod -c "<path to common_top>/admin/scripts/<context_name>/ adapcctl.sh graceful"
        fi
   endscript
}

Mine is set up to rotate when the error_log, error_log_pls, and mod_jserv.log reach 1mb in size. It will truncate copy the old log to <log>.n, truncate the old log, then compress the copy. 9 copies will be kept.

You can, of course configure this however you like.

The key part is the graceful apache restart after the log rotation. Sometimes rotating the logs can wedge the apache daemon, so a graceful restart is nice.

Hope that helps a bit - logrotate is a great tool. I use it for alert logs, listener logs, apache logs, etc.
Chuck



On Oct 16, 2009, at 8:26 AM, kathy duret wrote:

I am using the rotatelog function for my Apache logs.

ErrorLog "|/u01/Apache/Apache/bin/rotatelogs
/u01/app/oracle/product/sso10g/Apache/Apache/logs/error_log.%Y%m%d 86400"

While this does rotate the logs every 24 hours with a datetime, I specifically need to have it run at midnight.

Yes, I have an SR open and yet I posted to Apache forums.

There is a transferlog function but I haven't been able to get this to work I thought if I could manually force a rotate, then I could just cron this to go at midnight.

Happy Friday.

K




Other related posts: