January 18, 2004

Now that's some serious logging!

When I got an email yesterday from the cron daemon on one of my servers telling me that logrotate segfaulted because it couldn't create a file, I thought perhaps some process had gotten out of control writing to a logfile and filled up the partition where /var/log lives. Imagine my surprise when I went to the /var/log directory, attempted to do an "ls -l", and then waited--and waited--and waited. Odd. Eventually the listing kicked off, and started listing thousands of files with names like "mgetty.log.ttyS0.1.1.1.2.4.1.2.1.1". I finally killed the listing after twenty minutes or so; it was currently listing files with names like "mgetty.log.ttyS0.2.2.1.1.1...". There must be hundreds of thousands of them. Oh goody.

And why is mgetty running anyway? This is a hosted server in a large data warehouse. Are they seriously connecting modems to these things?

Well, googling for "mgetty.log.tty files" quickly identified the culprit as a bad entry in /etc/logrotate.d/mgetty that gets shipped with standard RedHat distributions. The entry causes logrotate to rotate all files that match "mgetty.log.ttyS*". Oh that's just brilliant. This will cause logrotate to rotate not only the real mgetty.log.ttyS0 file, but also every rotated logfile, and then every rotated rotated logfile, and then every--well, you get the idea.

So . . . yikes! Some calculations based on how often this log file gets rotated and the size of the /var/log directory itself--just over 30 meg--leads me to believe that there are probably about half a million of the mgetty.log files in my /var/log directory!

I'm running "find /var/log -name 'mgetty.log.ttyS0.*' -exec rm -v {} \;" to get rid of the all the offending files. It's been running now for well over an hour.

The final challenge will be how to recover the space from the /var/log directory. Unless I'm mistaken, directory files in an ext3 file system will grow as needed but will not shrink on their own. So when these log files are all finally deleted--it will be interesting to see how long that actually takes--I'll be left with 30 meg of allocated but unused space on the drive. Any ideas? Shut down the log processes, create a new directory and move the subtree? Will that work without unforeseen side effects? That's the only thing I can think of. I've never faced this particular issue before, and I'd love to hear from anyone reading this who might have some ideas.

Posted by Ron Pacheco at January 18, 2004 11:43 AM
Comments

Found your post via google, searching on this same problem. This just happened to me as well. Please post if you find a solution to the disk space problem. Over 900,000 log files were created in my /var/log directory and the /var/log dir size is about 44mb. Would definitely like to free that up if possible.

thanks

Posted by: same problem at January 26, 2004 12:05 AM

Thank you for posting about this.

My mangaged host in a data-center did the same thing, unfortunately I just now found out about it. I have an even bigger log dir. Holy moly!

Did you ever resolve the free-space issue?

Thanks again,
-seebq

Posted by: seebq at April 28, 2004 03:42 PM

Rather than treating the symptom by removing the files from a cron job daily - the recursively-rotated files should not be created in the first place.

So the more correct solution is to fix the source of the problem, i.e. to fix the config file /etc/logrotate.d/mgetty to have a non recursive pattern for the file-spec:

/var/log/mgetty.log.ttyS?

Instead of:
/var/log/mgetty.log.*

Posted by: Sean D. at October 13, 2004 06:03 PM