LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-19-2012, 10:25 AM   #1
clozarks
LQ Newbie
 
Registered: Apr 2010
Posts: 16

Rep: Reputation: 0
Logrotate Custom Log File Problem


I am trying to rotate a custom log for an active process. I can successfully rotate the log from the command line using:
logrotate -f /etc/logrotate.d/customlog (where customlog is the config file)
config file customlog contains:
/home/user/customapp.log {
missingok
compress
notifempty
daily
rotate 5
size 1G
create 0664 user user}
The rotation works but the running process does not write to the newly created logfile. How do I rotate the log and recreate the original log so that the live running application will now write to the recreated original log file?

Thank you
Curt Swartzlander
cswartzlander@nwacc.edu
 
Old 04-19-2012, 10:43 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
well this is the applications problem, not logrotate. logrotate will generally hup the process writing to it to encourage it to close all files and reopen them, but if you application doesn't perform those actions on a hup then that's not an option. You can use the postrotate options to run a small amount of arbitrary code upon completion of the rotation, e.g. stopping and starting the program, or a final solution is to NOT replace the file - use the copytruncate option to clone the file and delete the contents, leaving the original file in place, but now empty. Again this has its own issues if the app writing to it tries to access the file after the end, but that's a fair few ways around your issue, so one should hopefully be good enough.
 
Old 04-19-2012, 11:08 AM   #3
clozarks
LQ Newbie
 
Registered: Apr 2010
Posts: 16

Original Poster
Rep: Reputation: 0
Chris, the copytruncate option worked perfectly! I would like to put this in cron as well now. I could just run the line that works in cron, but can I run the entire logrotate.d to rotate all system logs (i.e. logrotate -f /etc/logrotate.d/*)? Or is it more complex than that? If necessary I would be happy to open anothre thread for this additional request.

Again I really appreciate the help!

Curt
 
Old 04-19-2012, 11:10 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
you would not change the execution of logrotate here, you'd add additional config to logrotate.d and let the existing daily exexcution (usually 4am) just pick up that responsibility as well.
 
Old 04-19-2012, 11:21 AM   #5
clozarks
LQ Newbie
 
Registered: Apr 2010
Posts: 16

Original Poster
Rep: Reputation: 0
Chris how do I know if the job is running?

as uer "root"
[root@server logrotate.d]# crontab -l
no crontab for root

Where is it running?
 
Old 04-19-2012, 01:18 PM   #6
quarlington
LQ Newbie
 
Registered: Apr 2012
Distribution: Fedora, RHEL, Unbreakable
Posts: 4

Rep: Reputation: Disabled
Check cron's log file. It's located at /var/log/cron on my disto.
 
Old 04-19-2012, 08:24 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
Depends on the distro, but check all cron files/dirs under /etc and /var/spool/cron.
On RHEL, logrotate is in dir /etc/cron.daily
 
Old 04-20-2012, 03:03 AM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
root doesn't run logrotate on cron. the system crontab runs it *as* root... if you can see the subtle difference. /etc/crontab.

but yes, just look at the logs.
 
Old 04-20-2012, 10:43 AM   #9
clozarks
LQ Newbie
 
Registered: Apr 2010
Posts: 16

Original Poster
Rep: Reputation: 0
Smile

Thanks to all who replied. I do indeed see the logs for cron running the root crontab as well as the cron.hourly cron.daily etc.

Appreciate the help as this is working perfectly now!
 
  


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 duplicate log entry problem dman777 Linux - Software 3 01-01-2011 04:01 PM
logrotate log files rashmeepawar Linux - Server 1 10-21-2009 06:14 AM
Custom log file using iptables bobbera Linux - Server 0 03-17-2009 11:40 AM
Log Rotation using Logrotate keysorsoze Linux - General 4 04-13-2007 03:51 PM
How to add my log files in logrotate Groucho Slackware 2 10-03-2003 09:16 AM


All times are GMT -5. The time now is 05:02 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration