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 1am find /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 cron
crontab -e
(this will open the config file with vim ) :x
" and press enter installing new crontab
" on the command line Now 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.