LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 05-28-2008, 01:33 AM   #1
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 655

Rep: Reputation: 40
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
 
Old 05-28-2008, 01:59 AM   #2
aus9
Guru
 
Registered: Oct 2003
Posts: 5,056

Rep: Reputation: Disabled
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
 
Old 05-28-2008, 02:14 AM   #3
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 655

Original Poster
Rep: Reputation: 40
Quote:
Originally Posted by aus9 View Post
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
Thanks for the reply.

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.
 
Old 05-28-2008, 02:27 AM   #4
grizly
Member
 
Registered: Nov 2006
Location: Melbourne Australia
Distribution: Centos, RHEL, Debian, Ubuntu, Mint
Posts: 128

Rep: Reputation: 16
From:http://www.linux-mag.com/id/627
Quote:
When logrotate actually processes a log file, there are several phases to its activity. First, any commands in a prerotate section of the relevant configuration file entry are executed. Next, a numbered backup file is created. After that, any commands in the configuration entry’s postrotate section are executed (there are two examples above). Finally, the copied (old) log file is compressed (if requested). You can use the pre- and post-rotation hooks to perform whatever actions make sense within the context on your systems. For example, you could copy the oldest saved log file to a different location for backup to tape before it is overwritten by logrotate.
So yeah, it creates the .1 file first I guess.
 
Old 05-28-2008, 05:59 AM   #5
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 655

Original Poster
Rep: Reputation: 40
I found that "copytruncate" option to logrotate ensures that the inode doesn't change. Basically what is was looking for.
 
Old 08-24-2011, 12:34 PM   #6
pakseykin
LQ Newbie
 
Registered: Aug 2011
Posts: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by kenneho View Post
I found that "copytruncate" option to logrotate ensures that the inode doesn't change. Basically what is was looking for.
Once I also was looking for the explanation. So, I'll post it here.
- 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.

Last edited by pakseykin; 08-24-2011 at 12:35 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
logrotate Ronin_tekorei Linux - Newbie 2 02-07-2008 05:44 AM
Logrotate - did I get it right? Swakoo Linux - General 1 06-20-2006 05:14 AM
My Logrotate won't work with mySQL guarriman Fedora 3 05-30-2006 05:02 AM
Pix logging on syslog... logrotate does not work logicalfuzz Linux - Software 0 03-06-2006 12:04 AM
logrotate dominant Linux - Newbie 1 02-13-2004 09:28 AM


All times are GMT -5. The time now is 03:43 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration