logrotate simple question

I'm trying to limit the size of my log files for my web folder. access.log is getting so large that it is taking a while to access it.

It seems that I've done something because there are new log files created, but my log folder looks like this:

> access.log 0

error.log 0

access.log.1 0

error.log.1 0

access.log.2 80,413,564

error.log.2 3,718,266

Obviously, the log is rotating, but the information is all coming along to the new log rather than staying behind in the archive log.

Here is what I have. I added the following to /etc/logrotate.conf:

> # system-specific logs may be configured here

/home/user/public/website.org/log/*.log {

missingok

daily

rotate 30

create 640 root user

}

My /etc/cron.daily/logrotate looks like:

> #!/bin/sh

test -x /usr/sbin/logrotate || exit 0

/usr/sbin/logrotate /etc/logrotate.conf

Also, I'm not sure what the "test -x" line is about. Can I delete that??

Thanks in advance for any advice.

9 Replies

You need to reload apache after rotating log files, otherwise it'll keep writing to the old log file since it still has it open. From /etc/logrotate.d/apache2 on one of my systems,

/var/log/apache2/*.log {
        weekly
        missingok
        rotate 52
        compress
        delaycompress
        notifempty
        create 640 root adm
        sharedscripts
        postrotate
                if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ]; then
                        /etc/init.d/apache2 reload > /dev/null
                fi
        endscript
}

The 'postrotate' part is the key.

Thanks!

I'm a little afraid to copy and paste this exact code to the bottom of my config. Is there anything in there that I may need to change since I'm referencing the web access logs?

> postrotate

if [ -f ". /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}" ]; then

/etc/init.d/apache2 reload > /dev/null

fi

endscript

Or will this addition do the trick do you think?

Now this is happening:

> * Reloading web server config apache2

httpd not running, trying to start

(13)Permission denied: make_sock: could not bind to address [::]:80

(13)Permission denied: make_sock: could not bind to address 0.0.0.0:80

no listening sockets available, shutting down

Unable to open logs [fail]

Please help if you have an idea of what I may have done. Thanks!

Which distribution are you running, and which web server are you using? I assumed you were using Apache, which was probably incorrect.

I am. I'm running Ubuntu 10.04.

I've deleted the entire system specific log configuration and it is still not reloading apache2.

I really appreciate your help!

My ports.config file (I saw this was one possible issue, but mine seems OK):
> # If you just change the port or add more ports here, you will likely also

have to change the VirtualHost statement in

/etc/apache2/sites-enabled/000-default

This is also true if you have upgraded from before 2.2.9-3 (i.e. from

Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and

README.Debian.gz

NameVirtualHost *:80

Listen 80

# If you add NameVirtualHost *:443 here, you will also have to change

the VirtualHost statement in /etc/apache2/sites-available/default-ssl

to # Server Name Indication for SSL named virtual hosts is currently not

supported by MSIE on Windows XP.

Listen 443

Listen 443

Nevermind. Stupid mistake.

I'm learning (only a week into building a vps and I have no coding background) and I really appreciate your patience. I have it all correctly functioning now including your very helpful script! logs are now turning over properly.

The reason I couldn't reload apache was because I forgot that I had not su root. All that was required was sudo!

Like I said. Stupid mistake. :)

Cool! Good to know it is working. logrotate is right up there with etckeeper and sl on my should-be-installed-on-every-system list. :-)

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct