Question:
linux: how to roll a log file that is locked by another app?
2011-01-26 15:14:04 UTC
I'm using tomcat on redhat and it logs to a file called tomcat.out -- I want to keep a daily log of this file by renaming tomcat.out to something like tomcat_.out. Only problem is tomcat keeps a lock on this file so I can't rename it without breaking the log (tomcat stops logging to it). I tried using symlinks for it, but that failed too. any other ideas? what about named pipes (I don't know how to do that)...??

thanks in advance
Four answers:
Techwing
2011-01-26 15:20:06 UTC
Shut down the application that has it locked. There's a reason why applications lock files. When multiple writers exist for a single file, bad things happen, unless there's a complex real-time I/O management system to prevent conflicts (and that generally doesn't exist on Linux/UNIX systems).
2011-01-26 23:18:45 UTC
would cp tomact.out tomact_.out work? or is this not at all what you're looking for? it would copy the file over to a new file, and shouldn't be restricted by tomcat. You could make a cron job to do it whenever you wanted.
adaviel
2011-01-26 23:35:04 UTC
Many servers e.g. httpd use SIGHUP to reread configs and reopen logfiles. Not sure about tomcat. Check the docs.

e.g. /etc/logrotate.d/httpd

/var/log/httpd/*log {

missingok

notifempty

sharedscripts

postrotate

/bin/kill -HUP `cat /var/run/httpd.pid 2>/dev/null` 2> /dev/null || true

endscript

}
jplatt39
2011-01-26 23:27:42 UTC
I would use cp and cron to schedule a daily copy of it.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...