How does logrotate work?
Hi.
I've set up logrotate to rotate the log files from our java application. The log file is rotated whenever it hits the defined size limit. As far as I know there are noe signals needed to be sent to the java application when one rotates the logfile, so I've simply done this: /path/to/logfile.log { missingok notifempty size=5M rotate 20 } What I was wondering is this: How does logrotate rotate the file? Does it rename the file to logfile.log.1 and create a new logfile, or does it copy logfile.log to logfile.log.1 and empty the logfile.log? In other words, will logfile.log remain with the same file system inode? I'm afaid that the logging will fail if the inode changes unexpectedly. Regards, kenneho |
altho I am sure you are going to get a better answer, let me comment on your current style if I may.
missingok...no harm to leave in but I assume you have named the pathway to a real file so it can be deleted notifempty...well I suggest rotation occurs due to your size command so if empty no rotate so can be deleted. 2) It may take some time to get to 5 megs so why not lower it and see what happens? 3) inodes may be an issue for you if your application truly requires it....I do not doubt you....but inodes themselves do not affect the actual rotation. to see what your current inodes are try these commands in no particualr order stat /var/log/(nameoflog)....which output inode info ls -i /var/log.....will output inode and filenames but less info (if required) than stat |
Quote:
I set up a simple test regarding the inode issue, and found this: When logfile X rotates to X.1, the inode remains. It thus seems as logrotate merely renames X to X.1, and makes a new file X. I'm hoping this won't be a problem for the java application. Will test it now. |
From:http://www.linux-mag.com/id/627
Quote:
|
I found that "copytruncate" option to logrotate ensures that the inode doesn't change. Basically what is was looking for.
|
Quote:
- Option "copytruncate" helps to avoid issues when logrotate is allowed to move files instead (the issue is that the file handle used by the process generating logs is not be updated = file is not reopened). - Some servers processes have notification interface through signals (see default configuration for httpd), others may have some exotic ways to be notified (or no way at all). If restart of the server is acceptable, stopping it in "prerotate" and starting it in "postrotate" works for sure. |
All times are GMT -5. The time now is 03:17 PM. |