I have some webservices running on tomcat that make tasks on a quite big repository. After a few days of run I realized that the tomcat temp folder ($CATALINA_HOME/temp) contains a huge amount of files which may affect the server behavior. Is there any way to configure the temp folder in order to delete files older then a certain amount of time or to disable the temp folder if it's not needed?
If your files' life-times are max "10" minutes then you can use below cron job to periodically clean your temp directory.
Let's say your tomcat's temp directory is "/usr/server/tomcat7/temp":
Cron job notation:
0 1 * * * find /usr/server/tomcat7/temp -type f -mmin +10 -delete
Code description:
0 1 * * * --> everyday at 1amfind /usr/server/tomcat7/temp --> find files in directory "/usr/server/tomcat7/temp"-type f --> only the items whiches' types are "file"-mmin +10 --> only the ones older than "10" minutes-delete --> delete them
For the ones who are new to Cron:
How to set the Cron job (Centos version):
sudo yum install croncrontab -e (this will open the config file with vim):x" and press enterinstalling new crontab" on the command lineNow you are completely ready to go.
I think disabling the temp dir makes no sense as it is obvoiusly a requirement for the deployed app. File upload is usually implemented using temp files for example.
If I were you I would write a simple shell script for the cleanup and put it into the crontab for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With