logrotate doesn't rotate catalina.out
Solution 1
Since this is getting a lot of views, I will let you all know the solution I found.
I could not get logrotate to work on catalina.out, so sorry if that's what you're looking for.
What I was able to do is stop catalina.out from ever getting generated. To do this, I created a file called setenv.sh in apache-tomee-plus-7.0.4/bin, and put this line in it
export CATALINA_OUT="/dev/null"
When tomee is started up, it looks something like this in catalina.sh
eval $_NOHUP "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
-classpath "\"$CLASSPATH\"" \
-Djava.security.manager \
-Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \
-Dcatalina.base="\"$CATALINA_BASE\"" \
-Dcatalina.home="\"$CATALINA_HOME\"" \
-Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 "&"
so outputting to a file seems necessary to run this tomee in the background. outputting to /dev/null lets it output somewhere, but it just goes nowhere
Solution 2
This is an old case, I see that, but I felt I should add my solution as it does rotate the logs, which was the original question.
In my case, I set up the /etc/logrotate.d/tomcat file in more or less the same manner as Justin did in the initial question:
/<apache-location>/tomcat/logs/catalina.out {
daily
copytruncate
rotate 180
compress
missingok
maxsize 200M
}
(my apache location is weird, so substitute as appropriate. The rotate 180
keeps my logs for about 30 days, if my math isn't too far off (24h * 30 days = 720h --> if rotating every 4 hours, that yields 720 / 4 = 180 times --> keep 180 log files).)
but I trigger the execution from a normal cronjob, as such:
0 */4 * * * /usr/sbin/logrotate -vf /etc/logrotate.d/tomcat >> /var/log/cut.log 2>&1
To rotate daily, just adjust the first part of the cronjob to e.g. 0 0 * * *
(midnight every day).
The -vf options are to turn on verbose (for logging the cron) and to force the execution of the rotation. The /var/log/cut.log is a file I've added specifically for logging of the cron job. The >> /var/log/cut.log 2>&1
could of course be dropped.
I'm running the rotation/cron job as root user.
This seems to work on my systems, after having had a lot of trouble initially. Not sure that this is the ideal solution, but at least I've avoided that the catalina.out
grows into the heavens and above, which was my main goal, and I suspect also the goal with the original question...
Solution 3
It's easy with rotatelogs
from Apache.
Just the set env property:
CATALINA_OUT_CMD="/usr/sbin/rotatelogs -f $CATALINA_BASE/logs/catalina.out.%Y-%m-%d.log 86400"
It will create a named pipe catalina.out so it can be rotated without restarting Tomcat.
For more info see catalina.sh file.
Related videos on Youtube
Justin
Updated on June 04, 2022Comments
-
Justin almost 2 years
I am trying to use logrotate to rotate out tomcat's catalina.out automatically on a daily basis even though I can manually call logrotate and it works fine. I am using I have tried every solution out there, but I cannot get it to rotate. I am on Oracle Linux 7.5 which is basically RHEL 7.
Here are the steps I have taken:
I created a file /etc/logrotate.d/tomee.conf that looks like this:
/apache-tomee-plus-7.0.4/logs/catalina.out { su opc opc daily rotate 7 compress notifempty missingok copytruncate }
I can manually execute the logrotate and it works just fine using
sudo /usr/sbin/logrotate /etc/logrotate.conf
I also attempt to debug using
sudo /usr/sbin/logrotate -d /etc/logrotate.conf
and the output has no errors... rotating pattern: /apache-tomee-plus-7.0.4/logs/catalina.out after 1 days (7 rotations) empty log files are not rotated, old logs are removed switching euid to 1000 and egid to 1000 considering log /apache-tomee-plus-7.0.4/logs/catalina.out log needs rotating rotating log /apache-tomee-plus-7.0.4/logs/catalina.out, log->rotateCount is 7 dateext suffix '-20181211' glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' copying /apache-tomee-plus-7.0.4/logs/catalina.out to /apache-tomee-plus-7.0.4/logs/catalina.out-20181211 truncating /apache-tomee-plus-7.0.4/logs/catalina.out compressing log with: /bin/gzip switching euid to 0 and egid to 0 ...
But it still doesn't do it automatically daily.
I also know that logrotate is running because according to
/var/lib/logrotate/logrotate.status
, other logs are being rotated, but not catalina.outcat /var/lib/logrotate/logrotate.status logrotate state -- version 2 "/var/log/yum.log" 2018-11-29-18:44:14 "/var/log/up2date" 2018-9-17-19:0:0 "/apache-tomee-plus-7.0.4/logs/catalina.out" 2018-12-8-0:37:14 "/var/log/chrony/*.log" 2018-9-17-19:0:0 "/var/log/wtmp" 2018-12-3-17:48:49 "/var/log/spooler" 2018-11-29-18:44:14 "/var/log/btmp" 2018-12-3-17:48:49 "/var/log/iscsiuio.log" 2018-9-17-19:0:0 "/var/log/maillog" 2018-12-11-3:7:1 "/var/log/secure" 2018-12-11-3:7:1 "/var/log/messages" 2018-12-11-3:7:1 "/var/account/pacct" 2018-9-17-19:0:0 "/var/log/cron" 2018-12-11-3:7:1
notice that there are multiple entries that say it was rotated on 12-11, but catalina.out wasn't rotated since 12-8, but it still isn't rotating.
Any help is greatly appreciated. Thanks.
-
Philipp Grigoryev over 4 yearsHow about this fragment
considering log /apache-tomee-plus-7.0.4/logs/catalina.out log needs rotating