Saturday, April 18, 2009

Apache + rotatelogs

While trying to enable rotatelogs feature on Apache (httpd-2.2.3-22.el5.centos) on CentOS 5.3, I ran into a very odd issue.

httpd.conf
LogLevel warn
ErrorLog "|/usr/sbin/rotatelogs -l logs/error_log 5M"
CustomLog "|/usr/sbin/rotatelogs -l logs/access_log 5M" combined
When attempting to restart apache, I kept receiving the following error message:
# /etc/init.d/httpd start
Starting httpd: 1 Previous file handle doesn't exists logs/error_log.1240101000 [ OK ]

[root@ofmon02 httpd]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: 1 Previous file handle doesn't exists logs/error_log.1240098834 [ FAILED]


Apache instances would start, but no log file is created. apachectl configtest did not report any issues. Few times apache won't start at all

It turns out that when using rotatelogs, you have to specify absolute paths, which makes sense since the logs are getting piped to rotatelogs, and rotatelogs would not know what logs/error_log or logs/access_log refers too.

httpd.conf
LogLevel warn
ErrorLog "|/usr/sbin/rotatelogs -l /var/log/httpd/error_log 5M"
CustomLog "|/usr/sbin/rotatelogs -l /var/log/httpd/access_log 5M" combined

# /etc/init.d/httpd start
Starting httpd: [ OK ]



Cheers,
VVK

No comments:

Post a Comment