Things I don't want to look for twice..

logrotate doesn’t rotate from file exists error

So, I had the following config:

/var/log/remote/*/php/*.log /var/log/remote/*/apache2/*.log { 
 rotate 7
 create 640 rsyslog rsyslog
 /etc/init.d/rsyslog restart > /dev/null

Paths were valid, ownership of folders was root.root, still, I had sample.log which wouldn’t get renamed to sample.log.1 and new file wasn’t created either. Have been sitting on this for days now. Decided to redo the config (was actually a bigger one, removed every comment, removed everything it wasn’t needed for my test and ran logrotate with the new config, forced. And eventually after carefully reading the logs (used logrotate -vf /path/to/conf) I found out that:

error: error creating output file /var/log/remote/something/apache2/error.log.1.gz: File exists

Ok, the file existed. So what? It had the necessary permissions to delete/replace it. But, of course, it didn’t. Moreover, after getting this error, creating other sample.log.1 files didn’t work either so rotation failed. So I deleted that empty file (yes, it was empty) and retried the logrotate on my test config. Of course, it worked. Surely I couldn’t find any documentation on this, so next time it happens, try to run verbosely and check for “file exists” errors. That will explain strange logrotate behavior.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: